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

PPro Extendscript & Regex with variables

Contributor ,
Dec 01, 2022 Dec 01, 2022

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!

TOPICS
Error or problem , SDK

Views

560

Translate

Translate

Report

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

Votes

Translate

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

Copy link to clipboard

Copied

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...

Votes

Translate

Translate

Report

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
Contributor ,
Dec 01, 2022 Dec 01, 2022

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}/);

 

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.
 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

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

Votes

Translate

Translate

Report

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