re2js 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/build/index.cjs.cjs +3281 -3142
- package/build/index.cjs.cjs.map +1 -1
- package/build/index.esm.d.ts +16 -4
- package/build/index.esm.d.ts.map +1 -1
- package/build/index.esm.js +3281 -3142
- package/build/index.esm.js.map +1 -1
- package/build/index.umd.js +3281 -3142
- package/build/index.umd.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -353,6 +353,25 @@ RE2JS.compile('(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)')
|
|
|
353
353
|
|
|
354
354
|
Function support second argument `perlMode`, which work in the same way, as for `replaceAll` function
|
|
355
355
|
|
|
356
|
+
### Translating Regular Expressions
|
|
357
|
+
|
|
358
|
+
The `translateRegExp()` method preprocesses a given regular expression string to ensure compatibility with RE2JS.
|
|
359
|
+
It applies necessary transformations, such as escaping special characters, adjusting Unicode sequences, and converting named capture groups
|
|
360
|
+
|
|
361
|
+
```js
|
|
362
|
+
import { RE2JS } from 're2js'
|
|
363
|
+
|
|
364
|
+
const regexp = RE2JS.translateRegExp('(?<word>\\w+)') // '(?P<word>\\w+)'
|
|
365
|
+
|
|
366
|
+
RE2JS.matches(regexp, 'hello') // true
|
|
367
|
+
RE2JS.matches(regexp, '123') // true
|
|
368
|
+
|
|
369
|
+
const unicodeRegexp = RE2JS.translateRegExp('\\u{1F600}') // '\\x{1F600}'
|
|
370
|
+
|
|
371
|
+
RE2JS.matches(unicodeRegexp, '😀') // true
|
|
372
|
+
RE2JS.matches(unicodeRegexp, '😃') // false
|
|
373
|
+
```
|
|
374
|
+
|
|
356
375
|
### Escaping Special Characters
|
|
357
376
|
|
|
358
377
|
The `quote()` method returns a literal pattern string for the specified string. This can be useful if you want to search for a literal string pattern that may contain special characters
|
|
@@ -418,7 +437,7 @@ These factors combined make the RE2 vanilla JS port a valuable tool for develope
|
|
|
418
437
|
Some files like `CharGroup.js` and `UnicodeTables.js` is generated and should be edited in generator files
|
|
419
438
|
|
|
420
439
|
```bash
|
|
421
|
-
./tools/scripts/make_perl_groups.pl
|
|
440
|
+
./tools/scripts/make_perl_groups.pl > src/CharGroup.js
|
|
422
441
|
yarn node ./tools/scripts/genUnicodeTable.js > src/UnicodeTables.js
|
|
423
442
|
```
|
|
424
443
|
|