Skip to main content
K.Daube
Community Expert
Community Expert
Jul 1, 2021 1:19 PM UTC
Answered

\d no more working in RegEx

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?

This topic is closed to new replies. Start a new post to keep the conversation going.
frameexpert
frameexpertCorrect answer
Community Expert
Jul 1, 2021 1:41 PM UTC

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/;
www.frameexpert.com

4 replies

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
Jul 1, 2021 1:41 PM UTC

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/;
Translate
www.frameexpert.com
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
Jul 1, 2021 2:48 PM UTC

Oh my good, such a triviality....

Translate
Community Expert
Jul 1, 2021 1:22 PM UTC

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

Translate
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
Jul 1, 2021 1:34 PM UTC

The absolutely strange thing is this:

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

Translate