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
Copy file name to clipboardExpand all lines: README.md
+15-11Lines changed: 15 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,15 @@ This is an official plugin for [Regex+](https://github.com/slevithan/regex) that
9
9
> [!NOTE]
10
10
> Regex flavors vary on whether they offer infinite or fixed-depth recursion. For example, recursion in Oniguruma uses a default depth limit of 20.
11
11
12
-
Recursive matching is added to a regex via one of the following (the recursion depth limit is provided in place of *`N`*):
12
+
Recursive matching is added to a regex via the following syntax. The recursion depth limit is provided in place of *`N`*.
13
13
14
14
-`(?R=N)` — Recursively match the entire regex at this position.
15
-
-`\g<name&R=N>` or `\g<number&R=N>` — Recursively match the contents of the group referenced by name or number at this position. The `\g` subroutine must be *within* the referenced group.
15
+
-`\g<name&R=N>` or `\g<number&R=N>` — Recursively match the contents of the group referenced by name or number at this position. The `\g<…>` subroutine must be *within* the referenced group.
16
16
17
-
Multiple uses of recursion within the same pattern are allowed if they are non-overlapping. Named captures and backreferences are supported within recursion, and are independent per depth level. So e.g. `match.groups.name` is the value captured by group `name` at the top level of the recursion stack.
17
+
Details:
18
+
19
+
- Multiple uses of recursion within the same pattern are supported if they're non-overlapping.
20
+
- Named captures and backreferences are supported within recursion, and are independent per depth level. Given a result named `match`, `match.groups.name` is the value captured by group `name` at the top level of the recursion stack.
> **Note:**[`regex-recursion-cjs`](https://www.npmjs.com/package/regex-recursion-cjs) is a third-party CommonJS wrapper for this library. It might not always be up to date with the latest version.
51
+
> **Note:**[*regex-recursion-cjs*](https://www.npmjs.com/package/regex-recursion-cjs) is a third-party CommonJS wrapper for this library. It might not always be up to date with the latest version.
49
52
</details>
50
53
51
54
<details>
52
-
<summary>Using a global name (no import)</summary>
55
+
<summary>Using a global name in browsers</summary>
Following is an alternative that matches the same strings, but adds a nested quantifier. It then uses an atomic group to prevent the nested quantifier from creating the potential for [catastrophic backtracking](https://www.regular-expressions.info/catastrophic.html). Since the example above doesn't *need* a nested quantifier, this isn't an improvement but merely an alternative that shows how to deal with the general problem of nested quantifiers that create multiple ways to divide matches of the same strings.
The first example above matches sequences of non-parentheses in one step with the nested `+` quantifier, and avoids backtracking into these sequences by wrapping it with an atomic group `(?>…)`. Given that what the nested quantifier `+` matches overlaps with what the outer group can match with its `*` quantifier, the atomic group is important here. It avoids exponential backtracking when matching long strings with unbalanced parentheses.
122
126
123
-
In cases where you're you're repeating a single token within an atomic group, possessive quantifiers provide syntax sugar.
127
+
In cases where you're you're repeating a single token within an atomic group, possessive quantifiers (in this case, `++`) provide syntax sugar for the same behavior.
124
128
125
-
Atomic groups and possessive quantifiers are provided by the base Regex+ library.
129
+
Atomic groups and possessive quantifiers are [provided](https://github.com/slevithan/regex#atomic-groups) by the base Regex+ library.
Because the generated pattern is used without Regex+, you can't include extended syntax like insignificant whitespace, atomic groups, possessive quantifiers, or non-recursive subroutines.
181
+
Because the generated pattern is used without Regex+, you can't include Regex+'s extended syntax like insignificant whitespace, atomic groups, possessive quantifiers, or non-recursive subroutines.
178
182
179
183
## 🏷️ About
180
184
181
-
regex-recursion was created by [Steven Levithan](https://github.com/slevithan).
185
+
Created by [Steven Levithan](https://github.com/slevithan).
182
186
183
187
If you want to support this project, I'd love your help by contributing improvements, sharing it with others, or [sponsoring](https://github.com/sponsors/slevithan) ongoing development.
0 commit comments