Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

RegEx in condition builder

jaakko_jalo
Tera Contributor

Hello,

In the condition builder we now have the 'matches regex' operator. ...But what are all the regex we CAN use in it?
For example: beginning of line operator '^' does not play nicely with the condition builder in this case as it is assumed it means AND and will add a second condition when saving.

Is there some other character denoting beginning of line for the condition builder? What other exeptions might there be and do they have workarounds?

thanks in advance,
Jaakko Jalo

25 REPLIES 25

poyntzj
Kilo Sage

Not tried this, but based on the scripts I have, try adding a forward slash at the beginning and end of your condition



an example from a script




var regex = /\d{1,2}(st|rd|th)\s{1}(Jan|Feb|Mar|Apr|May|Jun|Jul|Apr|Sep|Oct|Nov|Dec)\s{1}\d{4}\s{1}(at)\s{1}\d{1,2}:\d{1,2}(hrs)/;  


it's the ^ symbol that is the issue.



/^.{4966}$/



When this regex value is saved, it vanishes and a new condition is added:



regex save.PNG


I see this slightly differently to you - I am on calgary.


I have the classification Criteria tab at the bottom, and I can add it and it looks OK



find_real_file.png


tydaeus
Kilo Explorer

I did some experimentation with the "match regex" condition within Eureka, and found a couple useful pieces of info:


  • The beginning of line is implicit at the beginning of the textbox regex, so you can omit the '^' if you're trying to match from beginning of line. For multiline matching, you need to explicitly match the end of line characters to avoid doing single line matching -- I'm not sure how those vary across platforms, but something like (\r|\n|\r\n) should take care of it.
  • It's based off of javascript regexes, but the contents of the field correspond to the javascript regex as it is within the enclosing forward slashes '/'. E.g.: if the box contains "some text" (minus quotes), the equivalent javascript regex would be similar to /^some text/. This means that it may not be possible to use the flags that would appear after the trailing slash.

salvadormarchan
Kilo Guru