match method behaviour changed from 3.5 to 4.1

Hi

We just found that the match method, i. e. xy.match() has changed between 3.5 and 4.1. Just to let you know in case you use this method.

For example, this code worked in 3.5:

if (source.match("^*Z"))

Not with 4.1 anymore, an error like quantifier * … is thrown.

This code works with 4.1

if (source.match("^\\*Z"))

May be anyone (form Servoy) can comment on this and similar changes to look for from version 3.5 to 4.1.

Best regards, Robert

Servoy 4 uses a newer version of Rhino, 1.6 if I’m correct. The new version has several fixes voor regular expressions and that probably made the difference in your case.

What exactly are you trying to match here? Strings starting with “Z"?
The problem is that "
” is a special character meaning “zero or more occurences”. If you want to match “*” literally, it needs to be escaped with a single backslash, so in your case:

source.match(/^\*Z/)

Hi Joas

Joas:
Servoy 4 uses a newer version of Rhino, 1.6 if I’m correct. The new version has several fixes voor regular expressions and that probably made the difference in your case.

It seems so …

Joas:
What exactly are you trying to match here? Strings starting with “*Z”?

Exactly.

Joas:
The problem is that “" is a special character meaning “zero or more occurences”. If you want to match "” literally, it needs to be escaped with a single backslash, so in your case:

source.match(/^\*Z/)

Yes I know, but these strings are given from the timetable. What’s the meaning of the first and last slash in your argument in match()? I did it without them but then I need the 2 backslashes as seen above in my example to match the *Z pattern, but it’s sort of strange I think and can’t explain it to myself.

Best regards, Robert

Hi Robert,

Robert Huber:
What’s the meaning of the first and last slash in your argument in match()?

That’s the JS notation of a regular expression.
You can use var r = new RegExp(“my expression”) or you use var r = /my expression/
For further reading check http://www.regular-expressions.info/javascript.html

Hope this helps