You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Subclassing RegExp and overriding exec is extremely useful for extending ECMAScript regular expressions. I think previous issues have pointed out that this is used by Babel. Other libraries using it include:
Regex+ does this to support transpiling extended regex syntax for atomic groups and regex subroutines (from PCRE, Perl, etc.) into native JS regexes. Emulating these features requires the addition of "emulation groups" that add anonymous capturing groups to a regex but should not affect the results of regex matches (e.g. they should not affect backreferences in the replacement strings/callbacks of String#replace/replaceAll, nor should they add to result arrays from RegExp#exec or String#match/matchAll, nor alter the results of String#split).
Popular syntax highlighting library that uses Oniguruma-To-ES for its JavaScript engine.
Subclassing RegExp and overriding exec is also useful in backcompat libraries for polyfilling named capturing as well as flags /y and /d. And it will likely be useful for pollyfilling future RegExp flags and syntax. Essentially, it's a great way to make all regex methods and regex-using string methods benefit from the polyfill, rather than having to reimplement much slower versions of all of the methods.
The readme for this proposal currently makes it sound like overriding exec is asking for a bad time, but it’s actually amazingly easy to use.
The text was updated successfully, but these errors were encountered:
I agree and feel the type IV example would be better addressed by instead changing re.test(str) to directly return re.exec(str) != null and dropping all the symbol methods.
Subclassing
RegExp
and overridingexec
is extremely useful for extending ECMAScript regular expressions. I think previous issues have pointed out that this is used by Babel. Other libraries using it include:String#replace
/replaceAll
, nor should they add to result arrays fromRegExp#exec
orString#match
/matchAll
, nor alter the results ofString#split
).Subclassing
RegExp
and overridingexec
is also useful in backcompat libraries for polyfilling named capturing as well as flags/y
and/d
. And it will likely be useful for pollyfilling futureRegExp
flags and syntax. Essentially, it's a great way to make all regex methods and regex-using string methods benefit from the polyfill, rather than having to reimplement much slower versions of all of the methods.The readme for this proposal currently makes it sound like overriding
exec
is asking for a bad time, but it’s actually amazingly easy to use.The text was updated successfully, but these errors were encountered: