Copy link to clipboard
Copied
Basically, I'm trying to figure out how to search through a string and find all instances of certain strings that take the form of a prefix, followed by 6 digits, and then a suffix. The prefix and suffix won't always be the same. The following works in standard javascript, but line 4 gives me a syntax error when I run in Ppro.
var newNameStart = 'AAA';
var newNameEnd = 'ZZZ';
var replacer = 'REPLACED';
const regexFullText = new RegExp(`${newNameStart}\\d{6}${newNameEnd}`);
var testString = "XXXXXAAA658565ZZZXXXXXX";
var replacedString = testString.replace(regexFullText, replacer);
alert (replacedString);
This should output XXXXXREPLACEDXXXXXX.
Any ideas how to fix my regex to work with extendscript, or another way entirely to go about this? Thanks!
That's beyond my "PPro ExtendScript API" ken, but this page seems helpful:
https://eloquentjavascript.net/09_regexp.html
Copy link to clipboard
Copied
Here's PProPanel's use of RegExp; does this snippet work, locally, for you?
Copy link to clipboard
Copied
Yep, that works for me. and, replacing line 4 in my code with
const regexFullText = new RegExp(/|[0-9]{6}/);
Copy link to clipboard
Copied
That's beyond my "PPro ExtendScript API" ken, but this page seems helpful:
https://eloquentjavascript.net/09_regexp.html