This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Consideration for Perl-like (?[])
extended character classes instead of a flag
#39
Comments
Previous discussion: #2 |
Also, we are in the process of expanding the scope of our proposal slightly to fix problems with some existing syntax and semantics -- and that requires a new flag (which in turn gives us an opportunity to fix such problems). We had looked at the experimental Perl syntax; it is syntactically a real outlier compared with how other regex engines have extended their syntax. |
I do like the Perl syntax if we were to revisit the syntax-only route. |
mathiasbynens
added a commit
that referenced
this issue
Aug 20, 2021
mathiasbynens
added a commit
that referenced
this issue
Aug 23, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I've been researching regular expression syntax in various languages and engines to inform possible future proposals to expand the ECMAScript regular expression syntax. One of the features I've been reviewing is Perl's Extended Bracketed Character Classes, which support operations such as:
&
)+
or|
)-
)^
)!
)(
,)
)In this case, such a character class uses the tokens
(?[
and])
. The contents of the expression can contain the above tokens, whitespace (which is ignored), character classes, metacharacters (such as\p{..}
,\s
, etc.), and certain escape sequences (such as\x0a
, etc.). This allows you to write complex character classes like the following (based on the examples in the explainer):As well as classes like the following (from the perlre documentation):
# Matches digits in the Thai or Laotian scripts (?[ ( \p{Thai} + \p{Lao} ) & \p{Digit} ])
Currently,
(?[
is not valid RegExp syntax (with or without theu
flag), so it provides an opportunity to add syntax to cover set notation functionality without needing to introduce a new flag.The text was updated successfully, but these errors were encountered: