Forum Moderators: open

Message Too Old, No Replies

Regular Expressions

Unexpected Quantifier when non-greedy

         

joshie76

12:01 pm on Sep 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The following regular expression

var re = new RegExp("(.*object>" + sObj + ".*?selected>)false(<\/selected.*)","i")

Causes errors on some installs of IE and not on others: "Unexpected Quantifier". It's fine on about 80% of machines in the office but the remaining 20% seem to not like the '?' non-greedy* operator. The weird thing is that the failure doesn't stick to any one version of IE - it's happened on some 5.0 and some 5.5 machines whilst working on most of them.

It seems to work fine Netscape 7 too.

I've banged my head against a number of walls too many and it's time to call in the browser squad. Help me browser squad!

from JScript regular expression syntax guide:?When this character immediately follows any of the other quantifiers (*, +,?, {n}, {n,}, {n,m}), the matching pattern is non-greedy....

joshie76

12:42 pm on Sep 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I always do this. I spend ages trying to solve a problem, I post here and then it dawns on me seconds later. Maybe there's something about articulating a problem to others that just seems to help...

It turns out that it's all down to the Windows Scripting Engine Version (for VBScript and JScript) - Version 5.1 and below doesn't seem to support non-greedy patterns whereas 5.6 is fine. Grrr!

If anyone has any ideas on alternatives I'm all ears.