|
3 | 3 | [![npm version][npm-version-src]][npm-version-href] |
4 | 4 | [![bundle][bundle-src]][bundle-href] |
5 | 5 |
|
6 | | -This is an official plugin for the [`regex`](https://github.com/slevithan/regex) library that adds support for recursive matching up to a specified max depth *N*, where *N* must be between 2 and 100. Generated regexes are native `RegExp` instances, and support all JavaScript regular expression features except numbered backreferences (support could be added in future versions). |
| 6 | +This is an official plugin for the [`regex`](https://github.com/slevithan/regex) library that adds support for recursive matching up to a specified max depth *N*, where *N* can be between 2 and 100. Generated regexes are native `RegExp` instances, and support all JavaScript regular expression features except numbered backreferences (support could be added in future versions). |
7 | 7 |
|
8 | 8 | Recursive matching is added to a regex via one of the following: |
9 | 9 |
|
10 | 10 | - `(?R=N)` — Recursively match the entire regex at this position. |
11 | | -- `\g<name&R=N>`, `\g<N&R=N>` — Recursively match the contents of the group referenced by name or number at this position. |
12 | | - - The `\g` subroutine must be called *within* the referenced group. |
| 11 | +- `\g<name&R=N>` or `\g<number&R=N>` — Recursively match the contents of the group referenced by name or number at this position. |
| 12 | + - The `\g` subroutine must be *within* the referenced group. |
13 | 13 |
|
14 | | -Recursive matching supports named captures and named backreferences, which are independent per depth level. So e.g. `groups.name` on a match object is the value captured by group `name` at the top level of the recursion stack. |
| 14 | +The recursion depth limit is provided where *`N`* is shown above. |
| 15 | + |
| 16 | +Recursive matching supports named captures and backreferences, which are independent per depth level. So e.g. `groups.name` on a match object is the value captured by group `name` at the top level of the recursion stack. |
15 | 17 |
|
16 | 18 | ## Install and use |
17 | 19 |
|
@@ -69,7 +71,7 @@ re.test('aaabbb'); // → true |
69 | 71 | re.test('aaabb'); // → false |
70 | 72 | ``` |
71 | 73 |
|
72 | | -Note the `^` and `$` anchors outside of the recursive subpattern. |
| 74 | +Notice the `^` and `$` anchors outside of the recursive subpattern. |
73 | 75 |
|
74 | 76 | ### Match balanced parentheses |
75 | 77 |
|
@@ -98,7 +100,7 @@ const parens = regex({flags: 'g', plugins: [recursion]})` |
98 | 100 |
|
99 | 101 | This matches sequences of non-parens 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 parens. |
100 | 102 |
|
101 | | -Atomic groups are provided by the base `regex` library. |
| 103 | +[Atomic groups](https://github.com/slevithan/regex#atomic-groups) are provided by the base `regex` library. |
102 | 104 |
|
103 | 105 | ### Match palindromes |
104 | 106 |
|
@@ -137,7 +139,7 @@ Notice the `\b` word boundaries outside of the recursive subpattern. |
137 | 139 |
|
138 | 140 | <!-- Badges --> |
139 | 141 |
|
140 | | -[npm-version-src]: https://img.shields.io/npm/v/regex-recursion |
| 142 | +[npm-version-src]: https://img.shields.io/npm/v/regex-recursion?color=78C372 |
141 | 143 | [npm-version-href]: https://npmjs.com/package/regex-recursion |
142 | | -[bundle-src]: https://img.shields.io/bundlephobia/minzip/regex-recursion?label=minzip |
143 | | -[bundle-href]: https://bundlephobia.com/package/regex-recursion |
| 144 | +[bundle-src]: https://img.shields.io/bundlejs/size/regex-recursion?color=78C372&label=minzip |
| 145 | +[bundle-href]: https://bundlejs.com/?q=regex-recursion&treeshake=[*] |
0 commit comments