Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PPro Extendscript & Regex with variables

Engaged ,
Dec 01, 2022 Dec 01, 2022

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!

TOPICS
Error or problem , SDK
856
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Dec 02, 2022 Dec 02, 2022

That's beyond my "PPro ExtendScript API" ken, but this page seems helpful: 

https://eloquentjavascript.net/09_regexp.html

Translate
Adobe Employee ,
Dec 01, 2022 Dec 01, 2022

Here's PProPanel's use of RegExp; does this snippet work, locally, for you?



https://github.com/Adobe-CEP/Samples/blob/5490c33ac8355ba394c693deb10414553b0a5685/PProPanel/jsx/PPR...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 01, 2022 Dec 01, 2022

Yep, that works for me. and, replacing line 4 in my code with 

 

const regexFullText = new RegExp(/|[0-9]{6}/);

 

works insomuch as it finds the 6 digits in the middle and returns XXXXXAAAREPLACEDZZZXXXXXX.. I just can't seem to figure out how to include those variables that define the prefix and suffix of the 6 digits.
 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Dec 02, 2022 Dec 02, 2022
LATEST

That's beyond my "PPro ExtendScript API" ken, but this page seems helpful: 

https://eloquentjavascript.net/09_regexp.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines