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?
1 person found this helpful
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.
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.
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 );
Match : true RegExp.$1 : 2011- RegExp.$2 : 2011 RegExp.$3 : 11- RegExp.$4 : 11 RegExp.$5 : 03
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.
I confirm the same results both in CS5.5 and CS3 (the versions I can check) - It leads to conclusion that CS3 implementation of RegExp was wrong too.
I believe that this is the same problem - just the guys from Adobe made a mess with the implementation