- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 03:33 AM
Hii Team,
i want to create a regex or a pattern which can be used to filter data based on following criteria
Exclude names which starts with "!"
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 03:45 AM
Try to use the following pattern
^(?!\!).*
Mark it as helpful if it worked
Gaurav Vaze
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 03:42 AM
This works
regex = /^!/;
Try this in a background script
var regex = /^!/;
var name = "!test";
var result = regex.test(name);
gs.info(result);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 04:26 AM
Hii @Anurag Tripathi
i am getting the result as "true" for the script you have mentioned. but what i need is that the name which starts with ' ! ' should not be shown in the list.
can you please confirm.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 05:27 AM
its the same,
You can try with different test case is name and test. it will return true when ! is at the start.
!youvraj
You!raj
Youvraj!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 03:44 AM - edited 06-27-2024 07:38 AM
Hi @YUVRAJS,
Confirming via regex tester (https://regex101.com/), try the following:
- /^[!]
- (or) /^[!]/gm
However, key question, can I ask why we need a 'regex match' for a check when a name starts with? You can easily manage this via the 'starts with' condition.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie