Proposal for exact matching and matching at a position in RegExp
Steve L.
steves_list at hotmail.com
Tue Feb 9 23:46:06 PST 2010
>> http://andychu.net/ecmascript/RegExp-Enhancements-2.html
>>
>> Basically the proposal is to add parameters which can override the
>> internal state of the RegExp.
>
> Does anyone have any comments on this?
>
> Can I put it in a place where it will be considered for the next
> ECMAScript? The overall idea seems relatively uncontroversial since
> it was already implemented by Mozilla (for the exact same reason). I
> have proposed a specific API enhancement too.
I do not believe it was implemented for "the exact same reason." It seems
you are merely looking for a way to match exactly at a given character
position, and you correctly note that /y is not an elegant solution for this
problem. However, although /y can be used to solve this problem, my
understanding is that it was designed to work similarly to the \G regex
token from Perl/PCRE/Java/.NET/etc. while tying in nicely with the lastIndex
property. An important feature of /y (and \G from other regex flavors) is
that, with global regexes (compiled with /g), each successive match must
start where the last match ended. This is a very useful feature for writing
some types of simple parsers, etc. And in the process of smartly solving
this problem, you get an inelegant solution to your problem as a side
effect, free of charge.
Steven Levithan
http://blog.stevenlevithan.com
More information about the es-discuss
mailing list