Skip to content

Commit 580cc5d

Browse files
committed
Readme tweaks
1 parent e61dcdf commit 580cc5d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ re.test('aaabbb'); // → true
6868
re.test('aaabb'); // → false
6969
```
7070

71+
Note the `^` and `$` anchors outside of the recursive subpattern.
72+
7173
### Match balanced parentheses
7274

7375
```js
@@ -85,15 +87,15 @@ const parens = regex({flags: 'g', plugins: [recursion]})`\(
8587
] */
8688
```
8789

88-
Here's an alternative that matches the same strings, but adds a nested quantifier. It then uses an atomic group to prevent this nested quantifier from creating the potential for runaway backtracking:
90+
Following is an alternative that matches the same strings, but adds a nested quantifier. It then uses an atomic group to prevent this nested quantifier from creating the potential for [catastrophic backtracking](https://www.regular-expressions.info/catastrophic.html).
8991

9092
```js
9193
const parens = regex({flags: 'g', plugins: [recursion]})`\(
9294
( (?> [^\(\)]+ ) | (?R=50) )*
9395
\)`;
9496
```
9597

96-
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 runaway backtracking when matching long strings with unbalanced parens.
98+
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.
9799

98100
Atomic groups are provided by the base `regex` library.
99101

@@ -130,4 +132,4 @@ const palindromeWords = regex({flags: 'gi', plugins: [recursion]})`\b
130132
// → ['Racecar', 'ABBA']
131133
```
132134

133-
Note the word boundaries (`\b`) at the beginning and end of the regex, outside of the recursive subpattern.
135+
Note the `\b` word boundaries outside of the recursive subpattern.

0 commit comments

Comments
 (0)