Proposal for exact matching and matching at a position in RegExp

Erik Corry erik.corry at gmail.com
Tue Feb 9 03:39:47 PST 2010


2010/2/9 Andy Chu <andy at chubot.org>:
> On Wed, Jan 27, 2010 at 10:03 PM, Andy Chu <andy at chubot.org> wrote:
>> (The original message was held up in spam moderation for awhile)
>>
>> Here is an addendum, after it was pointed out to me that this issue
>> has come up before:
>>
>> 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?

I think it would be nice to have this feature.  For example the
Windscorpion xml test would run must faster with such an option.

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) {
  ...
}

I think that using the length property on the function is going to be
unreliable given the existing variation in those values.

The way we do regexps in V8 the 'y' is part of the regexp and we would
have to recompile the regexp to handle with or without 'y'.  In other
words in our implementation we have an implict ".*?(" at the start of
the regexp that indicates that there is a non-greedy match-anything
before the 0th capture parenthesis.  This is a pretty fast and clean
approach.  I think having something that matched 'the point where
searching started' would be more flexible than the global Y flag.
Then you could use it like '^' as one part of an alternation.   Perl
uses \G for the same concept and I think following that would be fine.
 To test for the presence of the feature you could use

!/\Gx/.test("Gx")

which returns true if the feature is implemented.

>
> 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.
>
> thanks,
> Andy
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list