5 Replies Latest reply on Nov 15, 2019 2:05 PM by Kaushik KM

    match_regex issue/question

      Share This:

      I need assistance to why my match_regex is not working correctly. My regex is only finding one match within my string and I'm not sure why. I need to pull out all the logfile names(test.log, test2.log, test3.log) from a string.

       

      Here is my string.

       

      test.log : Fatal error\ntest2.log : Fatal error\ntest3.log : Fatal error

       

       

      Here is my snippet of code.

       

      $FLDS = match_regex($EV.mc_parameter_value,'(.log)','');

      $EV.Module = listlen($FLDS);

      listwalk($FLDS,$Log);

      $EV.Notes = concat();

       

      Is my regex incorrect for pulling multiple expressions?

       

        • 1. Re: match_regex issue/question

          I think my post got screwed up. I'll try to place my code portion again.

           

           

          $FLDS = match_regex($EV.mc_parameter_value,'([^\n\s]*.log)*','');
            $EV.Module = listlen($FLDS);
            listwalk($FLDS,$Log);
            $EV.Notes = concat([$EV.Notes,' ',$Log]);

          • 2. Re: match_regex issue/question

            Is there an alternative method to parse this string without using match_regex? If I can parse this string at the newlines than maybe that could help get to the data I want to capture. How do I evaluate whether a string in a slot has a newline(non-printable) character located in it via mrl?

             

            If $E.slot contains '\n'          doesn't work.

            • 3. Re: match_regex issue/question

              Hi,

              I think the \n in you stringis literal - so in fact it is just a single line. So if you match without \n like "(\w\.log)"should do the trick.

               

              HTH,

              -Markus

              • 4. Re: match_regex issue/question

                The newline(\n) is not literal in my real string. It normally shows non-printable when you view it at the slot in IX. However, it is there. For this post, I had to somehow show readers that there is a newline there in my string so I visibly displayed it in the string.

                 

                I tried your expression and it did not work. It only pulled "t.log" and only one entry.

                 

                I also tried ([\w-])+\.log which does get the entire logname. However, it only gets the first one. I don't know if it is my regex that is not right or if it is the match_regex primitive that is not making it check globally.

                 

                If I did this in perl I would have something like:

                 

                $string =~ /([\w-])+\.log/g;          to match globally.

                 

                But in match_regex, how do I make it match globally to all info in my string that matches my expression?

                • 5. Re: match_regex issue/question
                  Kaushik KM

                  @Sherard_pulmano,

                   

                  were you able to achieve the above ?

                  to match globally. -- in match_regex function in MRL ?

                   

                  Thanks,

                  Kaushik KM