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

Hi Johnny - Update:


I tried many different things to get a report source working using "matches regex" - impossible.


There is still a problem ticket open with ServiceNow.


I checked it in Helsinki as well and there also appears this error: "Syntax Error or Access Rule Violation detected by database (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MATCH_RGX 'INC[0-9]{7}' GROUP BY timeref ORDER BY timeref' at line 1 Query is:..."


So unfortunately Development hasn't fixed this one yet.  


Yes, the MATCH_RGX needs to be replaced in several places with REGEXP, from what I understand.


Hi Johnny, this error is annoying.


I created a workaround. If you want to have a look: Re: Matches Regex in Condition Builder


hi Johnny,


I have a similar requirement like this.


I have a string like Building\Floor\Space\



My requirement - I want to replace all '\' with ',' and then split the result like:


Building


Floor


Space



How this can be achieved?? Looks like ServiceNow does not recognize '\' as a regex.


Hi Kunal,


here is a solution for your problem. It is all about escaping the backslashes.


Just try it in the browser console:



var t = "Building\\Floor\\Room"


var rex = new RegExp('\\\\','g');


var z = t.replace(rex,',\n');



Results in:


"Building,


Floor,


Room"



Hope it helps.