\R
Escape for ECMAScriptStage: 1
Champion: Ron Buckton (@rbuckton)
For detailed status of this proposal see TODO, below.
NOTE: See https://github.com/rbuckton/proposal-regexp-features for an overview of how this proposal fits into other possible future features for Regular Expressions.
The \R
escape sequence matches the various sets of code points that match a unicode line terminator, which can be difficult to write correctly.
See https://rbuckton.github.io/regexp-features/features/line-endings-escape.html for additional information.
\R
— Matches any line ending character sequence.NOTE: Requires the
u
orv
flags, as\R
is currently just an escape forR
without theu
flag.NOTE: Not supported inside of a character class.
u
or v
mode, \R
is roughly equivalent to the following pattern:
(?>\r\n?|[\x0A-\x0C\x85\u{2028}\u{2029}])
^
and $
in mu
modeu
or v
mode, \R
will continue to match the literal character R
.NOTE: The above example uses atomic groups
(?>)
to prevent backtracking when matching\r\n?
. Atomic groups is proposed here.
// split lines regardless of line termiantor style
const lines = fs.readFileSync("file.txt", "utf8").split(/\R/ug);
The following is a high-level list of tasks to progress through each stage of the TC39 proposal process: