- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 11:22 AM
Hello all,
I am attempting to use Regular Expressions. I am reading the documentation of: https://docs.servicenow.com/bundle/sandiego-application-development/page/script/general-scripting/co... and it says that I can use the j option to use for JavaScript based Regular Expressions. I am under the impression that I can use the g and j options with regular expressions. I have attached two screenshots. One screenshot just has the g option and SN does not complain. I then try to add the j option, and SN complains. What am I missing here?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 12:00 PM
When posting the code just be sure to format it by clicking the three dots icon, then the </> icon and select JavaScript. Should post without issue.
I just ran a test script against all 4 and it works using the j. I do get the orange ! in the editor, but it still works.
var re = new RegExp("(?<!HSF)[0-9]{3}( |-|)[0-9]{2}( |-|)[0-9]{4}(?![0-9])", "jg");
var testCases = ['123121234','lksjfd 123121234 lksjdf','hello world 123121234 bleh bleh bleh','you are a ding dong. HSF123121234'];
for (var i in testCases) {
gs.info('{0} = {1}', testCases[i], testCases[i].match(re).join(','));
}
Aoife
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 11:26 AM
Can you share the code you are using? I'll see if I can figure it out for you.
Aoife
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 11:34 AM
I have attached the regular expression in the attachment in this reply. I am terrified to post the actual code in the body since another post of mine was flagged as Spam because of my regular expression. What I am trying to accomplish with this regex is a Negative Lookbehind. I am attempting to ignore the strings that start with HSF.
Here is a simple data set:
123121234
lksjfd 123121234 lksjdf
hello world 123121234 bleh bleh bleh
you are a ding dong. HSF123121234
The only example that should be ignored is the last line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 12:00 PM
When posting the code just be sure to format it by clicking the three dots icon, then the </> icon and select JavaScript. Should post without issue.
I just ran a test script against all 4 and it works using the j. I do get the orange ! in the editor, but it still works.
var re = new RegExp("(?<!HSF)[0-9]{3}( |-|)[0-9]{2}( |-|)[0-9]{4}(?![0-9])", "jg");
var testCases = ['123121234','lksjfd 123121234 lksjdf','hello world 123121234 bleh bleh bleh','you are a ding dong. HSF123121234'];
for (var i in testCases) {
gs.info('{0} = {1}', testCases[i], testCases[i].match(re).join(','));
}
Aoife