RegEx in condition builder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2012 02:16 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2015 02:02 PM
Hi Jaakko,
I appreciate this may be a late response, but I just ran into this issue myself, so I thought I would post. The "matches regex" condition operator works well, but you have to know its secrets.
Here are a couple of tips (some of which came from earlier posts, so thanks all!)
- ServiceNow automatically adds a "/^" at the start of your RegEx condition
- This means that you'll need to account for it by adding a .* to the start of your RegEx in some cases, depending on your match criteria
- You can use matching groups (haven't tried capture groups, but N/A in this case)
- for ex. [0,2,4,6,8] to check for a single character
- You can use special characters like '$' for the end of the string
- You can test your filter in a background script (must have the security_admin role)
Here's an example I ran into. A customer wanted to send out a survey every 20 incidents. There are a lot of ways to solve this, but I went for a simple solution using "matches regex" on the Number field.
Here's the condition:
.*[0,2,4,6,8]0$
To test it, I created the following Background Script:
//instantiate a filter using the MATCH_RGX condition string operator
var filter = new GlideFilter('numberMATCH_RGX.*[0,2,4,6,8]0$^EQ', '');
filter.setCaseSensitive(false);
// check to see if current matches condition
// Get a record that I expect to return as true for a match
var current = new GlideRecord('incident');
current.get('number', 'INC0011080');
//Check record
gs.print(filter.match(current, true));
// Get a record I expect to return false
current.get('number', 'INC0011081');
//Check record
gs.print(filter.match(current, true));
- Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2016 12:59 AM
Hi Chris,
I found your post helpful , however i am building some regex according but its working partially nit fully. can you please help.
Requirement = = Need to configure inbound action based on subject line which create incident if email meet this condition: "if subject line having any digit number between '0 to 9' & digit number must be 9 digit only then system creates new incident ". For eg: Test Requirement 123456778 (Subject Line) Or 'Requirement 123456789' Or '012345678 Test Require' (Subject Line)
I tried the below script and it works:
Script:-
if (email.subject.match([0-9]{9}))
{
}
But its not completely working with my requirement, if I have 9 digit number only in my subject line then it's working i.e.123456789 (Subject Line) Or 986754130 (Subject Line) but when I have some text in subject line along with 9 digit then its not working i.e. 'Test Requirement 123456778 (Subject Line) Or Requirement 123456789' Test Or '012345678 Test Require' (Subject Line)
So, basically we need to add something more in the above script so that system can read the full subject line and accept if it finds 9 digit number along with text or anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2016 08:46 AM
Hi Chris - I just posted a blog article GlideFilter and Regular Expression Match summarizing all I know about GlideFilter, and also referenced your post. Any feedback would be great. Thanks.
Please feel free to connect, follow, mark helpful / answer, like, endorse.
| John Chun, PhD PMP | ![]() |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2015 11:16 AM
I have a ticket or two open on this with ServiceNow. They are planning on maybe fixing it in a release after Geneva.
I really wanted to be able to match regex in the condition builder on Process Classifiers so that I could catch processes that are too long for the Linux kernel and therefore have a length greater than 4067. These processes, since they aren't completely captured by the process table, cannot be accurately process classified and I'd like to flag them for not processing.
I could probably do this with a Business Rule on insert into the process table but the Matches Regex operator on the Process Handler or Classifier would have been nicer and more immediately visible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2016 05:27 AM
Hi Johnny.
Have you heard anything new? I also have a ticket towards servicenow regarding using "matches regex" in assignment rules but they won't say ANYTHING about matches regex even when I explicitly ask for documentation.


