Skip to content

Commit 45194e4

Browse files
committed
Readme: use partial as a tag for more examples
1 parent 076ae1f commit 45194e4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[<img align="left" src="https://github.com/slevithan/awesome-regex/raw/main/media/awesome-regex.svg" height="45">](https://github.com/slevithan/awesome-regex) <sub>Included in</sub><br>
44
<sup>[Awesome Regex](https://github.com/slevithan/awesome-regex)</sup>
55

6-
`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.
77

88
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.
99

@@ -380,8 +380,8 @@ If you want to understand the handling of partial patterns more deeply, let's lo
380380
First, let's consider:
381381

382382
```js
383-
regex`[${partial('^')}]`
384-
regex`[a${partial('^')}]`
383+
regex`[${partial`^`}]`
384+
regex`[a${partial`^`}]`
385385
```
386386

387387
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
393393
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:
394394

395395
```js
396-
regex`(${partial(')')})`
397-
regex`[${partial(']')}]`
398-
regex`[${partial('a\\')}]]`
396+
regex`(${partial`)`})`
397+
regex`[${partial`]`}]`
398+
regex`[${partial`a\`}]]`
399399
```
400400
401401
But these are fine since they don't break out:
402402
403403
```js
404-
regex`(${partial('()')})`
405-
regex`[\w--${partial('[_]')}]`
406-
regex`[${partial('\\\\')}]`
404+
regex`(${partial`()`})`
405+
regex`[\w--${partial`[_]`}]`
406+
regex`[${partial`\\`}]`
407407
```
408408
409409
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
424424
```js
425425
// Not using `partial` for values that are not escaped anyway
426426
/* 1.*/ regex`\u${'000A'}`
427-
/* 2.*/ regex`\u{${partial('A}')}`
428-
/* 3.*/ regex`(${partial('?:')}…)`
427+
/* 2.*/ regex`\u{${partial`A}`}`
428+
/* 3.*/ regex`(${partial`?:`}…)`
429429
```
430430
431431
These last examples are all errors due to the corresponding reasons below:

0 commit comments

Comments
 (0)