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

\d no more working in RegEx

Community Expert ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

In 2018 I developed a script which contains this regex:

 

var re_TmpVarName = new RegExp("(#zz)?\d+\-\d+\-\d+T\d+:\d+:\d+\.\d+Z");

 

to find variables named for example #zz2016-11-10T09:46:52.136Z

Now it turns out that (even in FM-15) the \d is no more working. I need to replace it by [0-9]:

 

main ();

function main () {
  var sName = "#zz2016-11-10T09:46:52.136Z";
//varr re_TmpVarName = new RegExp("(#zz)?\d+\-\d+\-\d+T\d+:\d+:\d+\.\d+Z");
  var re_TmpVarName = new RegExp("(#zz)?[0-9]+\-[0-9]+\-[0-9]+T[0-9]+:[0-9]+:[0-9]+\.[0-9]+Z");
  var aa = re_TmpVarName.test(sName);
  $.writeln (aa); // should be true
}

 

What is going on here?

TOPICS
Scripting

Views

154

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

Community Expert , Jul 01, 2021 Jul 01, 2021

Klaus, when you create a RegExp object, you have to escape the backslashes by doubling them (\\d). Alternatively, you can just use this syntax:

var re_TmpVarName = /(#zz)?\d+\-\d+\-\d+T\d+:\d+:\d+\.\d+Z/;

Votes

Translate

Translate
Community Expert ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

Hi Klaus,

 

I do not know about the usage in ExtendScript scripts.

In the regular Find dialog \d works.

FrameMaker 16.0.2.916

 

Best regards

 

Winfried

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
Community Expert ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

The absolutely strange thing is this:

the FMcalc script suite with the above mentioned regex still works correctly , but not in this simple test...

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
Community Expert ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

Klaus, when you create a RegExp object, you have to escape the backslashes by doubling them (\\d). Alternatively, you can just use this syntax:

var re_TmpVarName = /(#zz)?\d+\-\d+\-\d+T\d+:\d+:\d+\.\d+Z/;

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
Community Expert ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

LATEST

Oh my good, such a triviality....

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