ECMA-262 Mode in Regex Forge
Introduction
Regular expressions differ between programming languages and engines, with ECMA-262 (JavaScript regex) having specific limitations compared to PCRE, .NET, or Python.
To help developers write ECMA-262-compliant regex patterns, Regex Forge includes a built-in validation mode called ECMA-262 Mode. When enabled, this mode detects unsupported syntax and displays a warning in the status bar.
This document outlines all the unsupported regex features in ECMA-262 that Regex Forge validates.
Unsupported Features in ECMA-262
1. Unsupported Escape Sequences
\Q...\E
(Quoted Literal Escape) – not supported in ECMA-262.
2. Unsupported Special Escape Characters
\a
(Bell Character)\e
(Escape Character)
3. Unsupported Word Boundaries
\y
,\m
,\<
(Start of word boundary)\Y
,\M
,\>
(End of word boundary)
4. Invalid Character Ranges
- ECMA-262 does not allow certain character class ranges, especially when involving escape sequences.
5. Unsupported String Anchors
\A
(Start of string, use^
instead)`
(Backtick as start-of-string anchor, use^
instead)\Z
(End of string before final line break, use$
instead)\z
(Absolute end of string, use$
instead)\'
(Apostrophe as end-of-string anchor, use$
instead)
6. Unsupported Forward References
- References to capturing groups before they are defined (e.g.,
\1
before a capturing group).
7. Unsupported Mode Modifiers
- Global mode modifiers:
(?i)
,(?s)
,(?m)
,(?x)
,(?n)
. - Local mode modifiers inside groups:
(?ismxn:group)
. - Mode modifiers using the minus sign:
(?-i-s-m-x-n)
.
8. Unsupported Atomic Groups
(?>regex)
– atomic groups are not supported.
9. Unsupported Possessive Quantifiers
?+
,*+
,++
,{m,n}+
– possessive quantifiers are not allowed.
10. Unsupported Lookbehind Assertions
(?<=text)
(Positive Lookbehind)(?<!text)
(Negative Lookbehind)
11. Unsupported Start of Match Anchor
\G
(Start of match attempt).
12. Unsupported Conditional Expressions
(?(?=regex)then|else)
– conditional expressions are not supported.
13. Unsupported Inline Comments
(?#comment)
– inline comments are not allowed in ECMA-262.
14. Unsupported Unicode Features
\X
(Unicode Grapheme Clusters).\x{0}
through\x{FFFF}
(Extended Unicode Character Escape).\p{L}
,\p{Nd}
,\p{P}
, etc. (Unicode Properties).
15. Unsupported Named Capturing Groups & Backreferences
(?<name>regex)
(.NET-style named capturing group).(?'name'regex)
(.NET-style named capturing group).\k<name>
(.NET-style named backreference).\k'name'
(.NET-style named backreference).
16. Unsupported XML Name Character Classes
\i
,\I
,\c
,\C
– XML shorthand character classes are not supported.
17. Unsupported Character Class Subtraction
[abc-[xyz]]
– character class subtraction is not allowed.
18. Unsupported POSIX Features
[:alpha:]
,[:digit:]
, etc. (POSIX Character Classes).[.span-ll.]
(POSIX Collation Sequence).[=x=]
(POSIX Character Equivalence).
Credits
Information about unsupported ECMA-262 features was sourced from this GitHub Gist by CMCDragonkai.
Conclusion
ECMA-262 Mode in Regex Forge ensures that regex patterns are fully compliant with JavaScript’s regex engine. By detecting unsupported syntax early, it prevents unexpected errors and inconsistencies when running regex patterns in JavaScript environments.
For the best experience, enable ECMA-262 Mode while working with JavaScript-based regex patterns in Regex Forge.