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
`regex` is a template tag for dynamically creating readable, high performance, native JavaScript regular expressions with advanced features. It's lightweight (5.6KB) and supports all ES2024+ regex features.
6
+
`regex` is a template tag for dynamically creating readable, high performance, native JavaScript regular expressions with advanced features. It's lightweight and supports all ES2024+ regex features.
7
7
8
8
Highlights include using whitespace and comments in regexes, atomic groups via `(?>…)` which can help you avoid [ReDoS](https://en.wikipedia.org/wiki/ReDoS), subroutines via `\g<name>` which enable powerful pattern composition, and context-aware interpolation of `RegExp` instances, escaped strings, and partial patterns.
9
9
@@ -380,8 +380,8 @@ If you want to understand the handling of partial patterns more deeply, let's lo
380
380
First, let's consider:
381
381
382
382
```js
383
-
regex`[${partial('^')}]`
384
-
regex`[a${partial('^')}]`
383
+
regex`[${partial`^`}]`
384
+
regex`[a${partial`^`}]`
385
385
```
386
386
387
387
Although `[^…]` is a negated character class, `^`***within*** a class doesn't need to be escaped, even with the strict escaping rules of flags <kbd>u</kbd> and <kbd>v</kbd>.
@@ -393,17 +393,17 @@ Both of these examples therefore match a literal `^`. They don't change the mean
393
393
Moving on, the following lines all throw because otherwise the partial patterns would break out of their interpolation sandboxes and change the meaning of their surrounding patterns:
394
394
395
395
```js
396
-
regex`(${partial(')')})`
397
-
regex`[${partial(']')}]`
398
-
regex`[${partial('a\\')}]]`
396
+
regex`(${partial`)`})`
397
+
regex`[${partial`]`}]`
398
+
regex`[${partial`a\`}]]`
399
399
```
400
400
401
401
But these are fine since they don't break out:
402
402
403
403
```js
404
-
regex`(${partial('()')})`
405
-
regex`[\w--${partial('[_]')}]`
406
-
regex`[${partial('\\\\')}]`
404
+
regex`(${partial`()`})`
405
+
regex`[\w--${partial`[_]`}]`
406
+
regex`[${partial`\\`}]`
407
407
```
408
408
409
409
Partials can be embedded within any token scope:
@@ -424,8 +424,8 @@ But again, changing the meaning or error status of characters outside the interp
424
424
```js
425
425
// Not using `partial` for values that are not escaped anyway
426
426
/* 1.*/ regex`\u${'000A'}`
427
-
/* 2.*/ regex`\u{${partial('A}')}`
428
-
/* 3.*/ regex`(${partial('?:')}…)`
427
+
/* 2.*/ regex`\u{${partial`A}`}`
428
+
/* 3.*/ regex`(${partial`?:`}…)`
429
429
```
430
430
431
431
These last examples are all errors due to the corresponding reasons below:
0 commit comments