ServiceNow ignores escape characters as a part of Regex patterns.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2022 01:31 AM
Hi,
I have a scenario wherein I will get the regex pattern from a third party api call in the schema. And this schema contains escape characters(\) as a part of the regex pattern. This pattern is a part of the key-value pair in one of the objects in schema which I receive from the third party. When I try to populate this pattern into a field or if I want to send this pattern for some client side validation, the escape characters are being ignored. Can anyone please suggest any working solution for this.? I have attached the screenshots for your reference.
To give you more context around this, when I directly use literals methods and append the pattern with escape characters everything works fine, and the validation happens with regex's test function. But when I dynamically want to read the schema and populate the content of the regex into a field the escape characters or either being ignored. Can anyone please suggest me how I can preserve my escape characters as a part of my pattern.
PS: I tried to use indexOf('\'), since the characters itself is being ignored this index will be -1 always.
Thanks,
Zab