Hello Everybody,
Please correct me, but I think, I found a serious problem with regular Expressions in Indesign CS5.5 (and possibly in other apps from CS5.5).
Let's start with simple example:
-------------
var range = "a-a,a,a-a,a";
var regEx = /(a+-a+|a+)(,(a+-a+|a+))*/;
alert( "Match:" +regEx.test(range)+"\nLeftContext: "+RegExp.leftContext+"\nRightContext: "+RegExp.rightContext );
-------------
What I expected was true match and the left and the right context should be empty. In Indesign CS3 that is correct BUT NOT in CS5.5.
In CS 5.5 it seems that the only first "a-a" is matched and the rest is return as the rightContext - looks like big change (if not parsing error in RegExp engine).
Please correct me if I am wrong.
The second example - how to freeze ID CS5.5:
-------------
var range = "a-a,a,a-a,a";
var regEx = /(a+-a+|a+)(,(a+-a+|a+)){8,}/;
alert( "Match:" +regEx.test(range)+"\nLeftContext: "+RegExp.leftContext+"\nRightContext: "+RegExp.rightContext );
--------------
As you can see it differs only with the {8,} part instead of *
Run it in CS5.5 and you will see that the ID hangs (in CS3 of course it runs flawlessly}.
The third example - how to freeze ID 5.5 in one line (I posted it earlier in Photoshop forum because similiar problem was called earlier):
---------------
alert((/(n|s)? /gmi).test('s') );
---------------
As you can guess - it freezes the CS5.5 (CS3 passes the test).
Please correct me if I am doing something wrong or it's the problem of Adobe.
Best regards,
Daniel Brylak
In reference to my previous message: After some digging, I think that the main problem is that regExp in CS5.5 works in non-greedy mode (despite the fact that the documentation says opposite)
I don't know any way to change it back to greedy mode.
After all it does not explain the possibility of freezing when executing some expressions.
I would be grateful if someone had any idea what am I doing wrong or maybe someone has workaround for that?
b.r.
Daniel
Hi Daniel,
Thanks for sharing. Really annoying indeed.
Just to complete your diagnosis, what you describe about CS.5 is the same in CS5, while CS4 behaves as CS3.
var range = "aaaaa";
var regEx = /(a+-a+|a+)(,(a+-a+|a+))*/;
alert([
"Match:" +regEx.test(range),
"LeftContext: "+RegExp.leftContext.toSource(), // => CS3/4: EMPTY -- CS5+: EMPTY
"RightContext: "+RegExp.rightContext.toSource() // => CS3/4: EMPTY -- CS5+: ",a,a-a,a"
].join('\r'));
So there is a serious implementation problem of the RegExp object from ExtendScript CS5.
I don't think it's related to the greedy modes. By default, JS RegExp quantifiers are greedy, and /a*/ still entirely captures "aaaaaa" in CS5+.
By the way, you can make any quantifier non-greedy by adding ? after the quantifier, e.g.: /a*?/, /a+?/, etc.
I guess that Adobe ExtendScript has a generic issue in updating the RegExp.lastIndex property in certain contexts—see http://forums.adobe.com/message/3719879#3719879 —which could explain several bugs such as the Negative Class bug —see http://forums.adobe.com/message/3510078#3510078 — or the problems you are mentioning today.
@+
Marc
Hi Marc,
Thans for the complement of diagnosis. I recently upgraded from CS3 to CS5.5 and was not able to check the behaviour in CS4 and CS5.
Getting to the point, you are right that it's not the greedy mode problem - I've checked some other simple examples and sometimes worked as expeced, and sometimes suddenly wrong (freezing the execution).
Well then, I reported the bug to Adobe(and I suspect, I was not the first one) - we will see what happens.
Best regards,
Daniel
I cannot be sure in whether it relates to this problem.
Please perform this sample code.
var str = "2011-11-03";
//var str = "11-03";
//var str = "03";
var regex = /^((\d+)-)?((\d+)-)?(\d+)$/;
$.writeln("Match : " + regex.test(str));
$.writeln("RegExp.$1 : " + RegExp.$1);
$.writeln("RegExp.$2 : " + RegExp.$2);
$.writeln("RegExp.$3 : " + RegExp.$3 );
$.writeln("RegExp.$4 : " + RegExp.$4 );
$.writeln("RegExp.$5 : " + RegExp.$5 );
I get:
Match : true RegExp.$1 : 2011- RegExp.$2 : 2011 RegExp.$3 : 11- RegExp.$4 : 11 RegExp.$5 : 03
It's right!
But, If str = "11-03" then
Match : true RegExp.$1 : 11- RegExp.$2 : 11 RegExp.$3 : RegExp.$4 : 03 RegExp.$5 : 03
RegExp.$4 captured "03" why?
and, If str = "03" then
Match : true RegExp.$1 : RegExp.$2 : 03 RegExp.$3 : RegExp.$4 : 03 RegExp.$5 : 03
RegExp.$2 captured "03"
I reported to Adobe site.
Daniel, Seuzo,
Just posted a basic ScriptUI dialog to make regex-testing easier:
http://www.indiscripts.com/post/2011/11/extendscript-regexp-tester
@+
Marc
North America
Europe, Middle East and Africa
Asia Pacific
Copyright © 2012 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).