Forum Discussion

kmassey1022's avatar
kmassey1022
New Contributor
2 years ago
Solved

aqString.StrMatches using Regular expressions not working

The following code is using regular expressions in a aqString.StrMatches statement and returns false when it should return true unless I'm coding it wrong.  Please help.

aqString.StrMatches("Job ID [0-9] completed successfully""Job ID 1234 completed successfully")

 

Thanks.

  • Hi,

     

    Try this:

    aqString.StrMatches("Job ID [0-9]+ completed successfully""Job ID 1234 completed successfully")

    ('+' added after [0-9])

     

    Does it help?

     

    P.S. https://regex101.com/ may be used to check if regex works as expected.

     

     

  • Yes it does.  Thank you!

    I'm curious as to why the plus sign works even though it's imbedded within the quoted string.  Is this just how this function accepts string concatenation?

  • AlexKaras's avatar
    AlexKaras
    2 years ago

    Hi,

     

    Plus sign here is a part of regex syntax. It means 'any digit from [0-9] range repeated one or more time'.

    Without it your regex looked for any single digit from [0-9] range and did not match because the source string contained more than one digit in a row.

     

    P.S. Visit regex101.com and enter your and my regex-es - the pane on the right will provide you with good description of what those regex-es are looking for.

     

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Try this:

    aqString.StrMatches("Job ID [0-9]+ completed successfully""Job ID 1234 completed successfully")

    ('+' added after [0-9])

     

    Does it help?

     

    P.S. https://regex101.com/ may be used to check if regex works as expected.

     

     

    • kmassey1022's avatar
      kmassey1022
      New Contributor

      Yes it does.  Thank you!

      I'm curious as to why the plus sign works even though it's imbedded within the quoted string.  Is this just how this function accepts string concatenation?

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        Plus sign here is a part of regex syntax. It means 'any digit from [0-9] range repeated one or more time'.

        Without it your regex looked for any single digit from [0-9] range and did not match because the source string contained more than one digit in a row.

         

        P.S. Visit regex101.com and enter your and my regex-es - the pane on the right will provide you with good description of what those regex-es are looking for.