Does the RegExp /y modifier require /g?
steves_list at hotmail.com
Mon Dec 24 08:44:57 PST 2007
(I emailed this to the list last night, but it doesn't seem to have gone
through. Sorry if this becomes a dupe.)
As far as I understand from ECMA-262 3rd Edition, the regexp.lastIndex
property is meaningless if a regexp does not use the /g modifier. Quoting
from E262v3 §184.108.40.206 (RegExp.prototype.exec):
> 4. Let i be the value of ToInteger(lastIndex).
> 5. If the global property is false, let i = 0.
So, e.g., the following returns true, although it would return false if /g
var re = /x/;
re.lastIndex = 2;
re.test("xyz"); // true
Given the above rule, my questions are:
1. Does ES4's /y (sticky) modifier have any meaning if the /g (global)
modifier is not also set?
2. What about with String.prototype.split and String.prototype.search, which
ignore the values of regexp.global and regexp.lastIndex?
The extend_regexps proposal on the wiki does not specifically mention these
points, and the sticky modifier does not appear to be implemented in the ES4
reference implementation (the sticky property gets set with /y, but it
doesn't appear to work).
I'm working on code which brings some of the ES4 regex features (including
/y) to current browsers, but I'm not sure which way to go on these points.
View this message in context: http://www.nabble.com/Does-the-RegExp--y-modifier-require--g--tp14488851p14488851.html
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com.
More information about the Es4-discuss