Does the RegExp /y modifier require /g?

2007-12-24 Thread StevenLevithan

(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 ยง15.10.6.2 (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 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.

___
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss


Re: Does the RegExp /y modifier require /g?

2007-12-24 Thread Brendan Eich
On Dec 24, 2007, at 8:44 AM, StevenLevithan wrote:

 (I emailed this to the list last night, but it doesn't seem to have  
 gone
 through. Sorry if this becomes a dupe.)

(I don't see a moderator request based on your sending from a  
different e-mail address -- I don't see a dup either.)

 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?

Yes.

 2. What about with String.prototype.split and  
 String.prototype.search, which
 ignore the values of regexp.global and regexp.lastIndex?

The /y flag makes unanchored regexps match or fail at the current  
position in the target string, period. Where the current position is  
may depend on /g and other things, but /y is independent (lower- 
level) than these considerations.

 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.

Firefox 3 is in beta release now and has supported /y since an early  
alpha. See https://bugzilla.mozilla.org/show_bug.cgi?id=371932.

/be

___
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss