Proposal for exact matching and matching at a position in RegExp

Brendan Eich brendan at mozilla.com
Tue Feb 9 09:58:58 PST 2010


On Feb 9, 2010, at 9:50 AM, Andy Chu wrote:

>> However, expanding the language by adding extra parameters to  
>> existing
>> functions is annoying because it means you can't test for the  
>> presence
>> of absence of the feature with a simple if:
>>
>> if (RegExp.funkyNewFunction) {
>> ...
>> }
>
> That's true, I would want to be able to test for the feature.  I think
> you could do it like this:
>
> if (new RegExp("a", "y").test("----a")) {
>  ... use y
> }
>
> Although perhaps something easier like RegExp.sticky or
> RegExp.feature('sticky') would be better.

SpiderMonkey (and possibly Rhino, I haven't checked) does reflect the  
y flag as the sticky property:

js> re = /hi/y
/hi/y
js> re.sticky
true
js> re = RegExp("hi", "y")
/hi/y
js> re.sticky
true
js> re2 = /bye/
/bye/
js> re2.sticky
false

I see no need to invent different and in-regexp syntax.

/be


More information about the es-discuss mailing list