Find a value between two strings using regex

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2019 11:01 AM
(originally posted under Now Platform)
I'm looking to parse a script field to find any messages that have been referenced in gs.getMessage() calls. The following regex works fine in any online test website but not in ServiceNow;
(?<=getMessage\(\").*?(?=\")
Here's the code I'm trying to use;
var regex = new RegExp(/(?<=getMessage\(\").*?(?=\")/g);
which returns the following error when tested/exec'd
Evaluator: com.glide.script.RhinoEcmaError: Invalid quantifier ?
Line(0) column(0)
Looks to me like the Positive Lookbehind is failing, but not sure of an alternative.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2019 11:45 AM
I check your reg expression at https://www.regextester.com/ and I get a message there the lookbehind is not supported in Javascript.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 12:48 AM
The message I was getting was that it wasn't supported in all browsers. Are there any alternatives then?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 05:11 AM
I'm not sure I follow you requirements. Can you give more details?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 07:06 AM
Sure, essentially I'm looking to scan through the script field for various records to see what custom messages are being referenced. So if there is a script such as the following;
/* display message */
alert(getMessage("Custom text message"));
/* get message and store */
var msg = getMessage("Store custom message");
I want to have the following returned;
Custom text message
Store custom message