Does the RegExp /y modifier require /g?

StevenLevithan steves_list at
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 § (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
were used:

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, which
ignore the values of 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:
Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at

More information about the Es4-discuss mailing list