Match Regex in Condition Builder

Bjoern3
Tera Guru

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. 

 

7 REPLIES 7

dunstanchristop
Tera Contributor

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

Denise Taylor2
Tera Guru

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.

DonJesusCarlos
Tera Contributor

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 ?