Repository navigation
Conversation
mathiasrw
marked this pull request as draft
October 24, 2026 21:41
…x, and drop regex+u
mathiasrw
marked this pull request as ready for review
October 24, 2026 21:45
mathiasrw
marked this pull request as draft
October 24, 2026 22:21
mathiasrw
marked this pull request as ready for review
October 24, 2026 22:27
…by default, and warn on $1 under n
…ped runs in the tests
This was referenced Oct 25, 2026
mathiasrw
marked this pull request as draft
October 25, 2026 22:24
…d the $1 warning, and fix [(?>]\1
mathiasrw
marked this pull request as ready for review
October 25, 2026 22:30
…oo, as regex/internals is an ES module only
…outine copies, the lookbehind and -u with regex+
…behind with an example
… of [[] and of 99 groups
…e train, as the PRs above change the same lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #500
Closes #854
Also closes #858
Change
Regex+ by Steven Levithan is now behind the engines of
-E:rr(the default, alsodefault)(?>…), possessive quantifiers likea++, and subroutines\g<name>with(?(DEFINE)…). Only the transforms of Regex+ run, not its flags.regex+runtime$1in the replacement, in--jscode and in--output-matchstill counts only the groups of the user. One exception: a subroutine copies the unnamed groups inside the group it calls, and those copies get numbers, as upstream does not hide them without a backreference. The README says so.--debugand--statuswith--verbosetell the engine and the added groups.--literalgives the text as it is with every engine, also with the free spacing ofregex+.--exclude-reuses the same engine and flags as the pattern, so all regex in a run work the same way.[(?>]\1is the same as in the native engine (Fix [(?>]\1 stopping the run with the rr engine #858).--flags
--flagssets the flags of the regex, likegimsv, in place of the defaults:gim, orgimvxnwith-E regex+. So-E regex+ --flags gimvxis Regex+ where all groups capture. It can not be used with-G,-I,-M,-sand-u,xandnneed-E regex+, an unknown flag stops the run with the flag named, a letter given twice counts once,--flagsgiven twice takes the last one, anduwithvstops the run with a message. With the flagy, each file, each name of--renameand each path for--exclude-restarts from the beginning, and not where the one before ended.Named groups in --js
A named group is
$and the name:(?<year>…)gives$year, and$year_has a space at the end. The groups come after the other variables, so a group named like a number, liken, wins over$n. A name may end with_. With the flagnonly named groups capture, so--jshas$0and the names, but no$1. (#863 makes the order of a group likea_and the cousin ofanot matter, and says that a replacement text still reads$1.)For the release note of v8
\g<name>. So a pattern that works today gives the same regex withrr. The one change:\g<name>was the textg<name>, and withrrit calls the group.-E runtimekeeps the old meaning.-E V8and-E JSCare gone.-E runtimeis the native engine.--jsare$year, not_year.Good to know: Regex+ emulates atomic groups and possessive quantifiers with a lookahead and a backreference, and a lookbehind reads from right to left, so inside a lookbehind they look forward in place of back and match in the wrong place, with no error.
-E regex+ -uusesuin place ofv. A subroutine needs a named group that exists, as Regex+ has no numbered ones like\g<1>. Both are in the README, and so are two limits: without-u, a[inside a class, like[[], hides the extended syntax after it (write[\[]), and counting the groups Regex+ adds, a replacement text can only reach the first 99 groups.Regex+ as a dependency
regex6.1.0 andregex-utilities2.3.0 are dependencies. The build bundles them, asregex/internalsandregex-utilitiesare ES modules only, and the build of the CLI is CommonJS. #862 builds RexReplace as an ES module, so they can be imported when it runs.The subroutines of
regexare not exported, sosrc/libshassubroutines.jsandutils-internals.jsas they are, and the three parts ofutils.jsthey use: 429 lines, with no changes. RexReplace runs the subroutines, the possessive quantifiers and the atomic groups itself, to know which groups they add. Forregex+,rewrite()runs with those turned off first. 65 patterns, with each of the flags v, x and n on and off, give the same regex and the same added groups as a patchedrewrite().regexandregex/internalsare two builds in the package, so the part both use is bundled twice. #862 takes the size down. When upstream exportssubroutines, the copy goes, andsrc/libs/README.mdsays how.Tests
test/fix/854.test.jschecks:rrgives the same regex as the native engine for 26 legacy patterns, like\",a],\01,[a++],[(?>]\1and[\g<x>].rrreads atomic groups, possessive quantifiers, subroutines andDEFINE, anddefaultisrr.$1,$2$1,$3(stays text),$10,--jsand--output-match.runtimereads\g<d>as text.regex+has free spacing, only named groups capture, and thevflag.V,V8,JSC,regex+n,regex+x,regex+uandregex+vare no engines, with the message checked.regex+stops the run on\", and--literalwithregex+findsa b #c (d)as it is.--flags: leaving outxorn, all flags set,uin place ofv,vwhen neither is given, a flag twice,--flagswith-Iin the CLI, and the message forxornwithoutregex+and for an unknown flag.--jswithnhas$0and the named groups, and$1is not defined. Withoutnthe numbers are back.The tests of #799, #815, #816 and #825 use
$yearnow.yarn test-cipasses.