Match Regex in Condition Builder

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2020 01:39 AM
Hi all, I was wondering if someone could set me right. I am trying to use the "matches regex" operator in the condition builder for an assignment rule. So I set:
Short Description - matches regex - /\bSAP\b
That does not work. I tried "/\bSAP\b", "./\bSAP\b", "/\bSAP\b/g", "/\bSAP\b/", "\bSAP\b" (without "" obviously)
All those work fine in the Regex tester, but I get no hit if I use it in Servicenow
What I am trying to do is find instances of SAP but not ASAP, disapear, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2021 11:30 AM
You have to escape twice i.e \\b so to the match function received \b as the anchor for word in regex. Its old no one answered it so, I just answered if someone need it in the future. HTH
Thanks,
DC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 02:35 PM
Check out this post. As explained there,
The regex for event rules is a bit more sensitive than that and the entire string has to be captured or it would only parse correctly if the entire beginning of the string was exactly the same each time. The Xplore regex tester unfortunately does not use the same backend regex as event management rules (nor does regex101 or most other popular testers).
So if your regex isn't working, try a .* at the beginning and/or end of your regex statement.
Also, it appears you can configure regex101 to test regex as per ServiceNow EM requirements. Check out this KB article.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 06:35 AM
Hello everyone,
thanks you for you return who help a bit.
i try also to make a UI Policy with conditional on a field with matches regex and it's not working on Sandiego Patch 10 hot fix.
my regex is = ^(?:.*\W){2,} <==> égal to (?:.*\/.*){2,}
but i try the both and anyone are not working.
for ma part i try to find on a field value contains "/" and i want to make a Ui ploici when i find 3 or more "/" in this field to show two anothers fields.
an example of the value of the field i made the regex : RA/DSP/CSP RH
i have an error like this :
com.glide.script.RhinoEcmaError: Cannot read property "1" from null
<refname> : Line(1) column(0)
==> 1: gs.getCssCacheVersionString().match(/^.*_(.*)&.*$/)[1]
how could you pleanse help me ?