Proposal for exact matching and matching at a position in RegExp
andy at chubot.org
Fri Feb 12 15:08:17 PST 2010
> \G is more flexible and it is rather similar to ^ conceptually.
> The mental model happens to be out of sync with how regexps are
> implemented. The implicit .*? at the start of a regexp is actually
> the fastest way to implement since you are using the fast internal
> search mechanisms that the regexp engine has rather than an external
> loop that repeatedly asks "does it match here?".
OK I see what you mean.
Actually the one I really care about is "pos". That one is obviously
a property of the match, and not the RegExp. I can't really think of
a real practical case where you would want a left-anchored match and a
search on the same RegExp.
So now that I know "/y" is already part of the RegExp in Mozilla, and
semantically (and implementation-wise) it is equivalent to removing
the leading .*?, it wouldn't bother me if it stayed that way. But
'pos' should be an argument. Obviously you will want multiple "pos"
arguments on the same RegExp.
(I think my vague recollection was the opposite of what I said -- that
a leading .*? is faster, while .search() could be slower. It would
make sense because the naive way to do .search() as you said is to try
matching a character at a time.)
More information about the es-discuss