rregex 1.8.1 → 1.8.2
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 +58 -276
- package/jsr.json +17 -0
- package/lib/cf.d.ts +1075 -0
- package/lib/cf.mjs +20 -0
- package/lib/commonjs.cjs +996 -0
- package/lib/commonjs.d.cts +1014 -0
- package/lib/esm.d.ts +1001 -0
- package/lib/esm.mjs +990 -0
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +34 -30
- package/lib/standalone.d.ts +1067 -0
- package/lib/standalone.js +1077 -0
- package/lib/types.d.ts +554 -556
- package/lib/web.d.ts +1075 -0
- package/lib/web.js +1080 -0
- package/package.json +90 -22
- package/lib/browser.d.ts +0 -1077
- package/lib/browser.js +0 -1207
- package/lib/commonjs.d.ts +0 -1020
- package/lib/commonjs.js +0 -1152
- package/lib/module.d.ts +0 -1020
- package/lib/module.js +0 -1135
package/lib/types.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
|
-
* Escapes all regular expression meta characters in `text`.
|
|
5
|
-
*
|
|
6
|
-
* The string returned may be safely used as a literal in a regular
|
|
7
|
-
* expression.
|
|
8
|
-
|
|
9
|
-
* @returns {string}
|
|
10
|
-
*/
|
|
4
|
+
* Escapes all regular expression meta characters in `text`.
|
|
5
|
+
*
|
|
6
|
+
* The string returned may be safely used as a literal in a regular
|
|
7
|
+
* expression.
|
|
8
|
+
*/
|
|
11
9
|
export function escape(text: string): string;
|
|
12
10
|
/**
|
|
13
11
|
* Represents a single match of a regex in a haystack.
|
|
@@ -18,21 +16,6 @@ export type Match = {
|
|
|
18
16
|
value: string
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
/**
|
|
22
|
-
* Captures represents a group of captured strings for a single match.
|
|
23
|
-
*
|
|
24
|
-
* The 0th capture always corresponds to the entire match. Each subsequent index
|
|
25
|
-
* corresponds to the next capture group in the regex. If a capture group is named,
|
|
26
|
-
* then the matched string is also available via the name property. (Note that the
|
|
27
|
-
* 0th capture is always unnamed and so must be accessed with the get property.)
|
|
28
|
-
*
|
|
29
|
-
* Positions returned from a capture group are always byte indices.
|
|
30
|
-
*/
|
|
31
|
-
export type Captures = {
|
|
32
|
-
get: Match[]
|
|
33
|
-
name: Record<string, Match>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
19
|
/**
|
|
37
20
|
* A high-level intermediate representation (HIR) for a regular expression.
|
|
38
21
|
*/
|
|
@@ -461,6 +444,21 @@ export type Repetition = {
|
|
|
461
444
|
sub: Hir
|
|
462
445
|
}
|
|
463
446
|
|
|
447
|
+
/**
|
|
448
|
+
* Captures represents a group of captured strings for a single match.
|
|
449
|
+
*
|
|
450
|
+
* The 0th capture always corresponds to the entire match. Each subsequent index
|
|
451
|
+
* corresponds to the next capture group in the regex. If a capture group is named,
|
|
452
|
+
* then the matched string is also available via the name property. (Note that the
|
|
453
|
+
* 0th capture is always unnamed and so must be accessed with the get property.)
|
|
454
|
+
*
|
|
455
|
+
* Positions returned from a capture group are always byte indices.
|
|
456
|
+
*/
|
|
457
|
+
export type Captures = {
|
|
458
|
+
get: Match[]
|
|
459
|
+
name: Record<string, Match>
|
|
460
|
+
}
|
|
461
|
+
|
|
464
462
|
/**
|
|
465
463
|
* The high-level intermediate representation for a capturing group.
|
|
466
464
|
*
|
|
@@ -486,561 +484,560 @@ export type Capture = {
|
|
|
486
484
|
}
|
|
487
485
|
|
|
488
486
|
/**
|
|
489
|
-
* A compiled regular expression for matching Unicode strings.
|
|
490
|
-
* @see https://docs.rs/regex/latest/regex/
|
|
491
|
-
*/
|
|
487
|
+
* A compiled regular expression for matching Unicode strings.
|
|
488
|
+
* @see https://docs.rs/regex/latest/regex/
|
|
489
|
+
*/
|
|
492
490
|
export class RRegex {
|
|
493
491
|
free(): void;
|
|
494
|
-
/**
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
*
|
|
504
|
-
|
|
505
|
-
*
|
|
506
|
-
* It is recommended to use this method if all you need to do is test
|
|
507
|
-
* a match, since the underlying matching engine may be able to do less
|
|
508
|
-
* work.
|
|
509
|
-
*
|
|
510
|
-
* # Example
|
|
511
|
-
*
|
|
512
|
-
* Test if some text contains at least one word with exactly 13
|
|
513
|
-
* Unicode word characters:
|
|
514
|
-
*
|
|
515
|
-
* ```typescript
|
|
516
|
-
* const text = "I categorically deny having triskaidekaphobia."
|
|
517
|
-
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
518
|
-
* ```
|
|
519
|
-
*
|
|
520
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
521
|
-
* @param {string} text - The string against which to match the regular expression
|
|
522
|
-
* @return {boolean}
|
|
523
|
-
*/
|
|
524
|
-
isMatch(text: string): boolean;
|
|
525
|
-
/**
|
|
526
|
-
* Returns the same as is_match, but starts the search at the given offset.
|
|
527
|
-
* The significance of the starting point is that it takes the surrounding
|
|
528
|
-
* context into consideration. For example, the `\A` anchor can only match
|
|
529
|
-
* when `start == 0`.
|
|
530
|
-
*
|
|
531
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
532
|
-
* @param {string} text - The string against which to match the regular expression
|
|
533
|
-
* @param {number} start - Zero-based index at which to start matching
|
|
534
|
-
* @return {boolean}
|
|
535
|
-
*/
|
|
492
|
+
/**
|
|
493
|
+
* Returns the same as is_match, but starts the search at the given offset.
|
|
494
|
+
* The significance of the starting point is that it takes the surrounding
|
|
495
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
496
|
+
* when `start == 0`.
|
|
497
|
+
*
|
|
498
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
499
|
+
* @param {string} text - The string against which to match the regular expression
|
|
500
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
501
|
+
* @return {boolean}
|
|
502
|
+
*/
|
|
536
503
|
isMatchAt(text: string, start: number): boolean;
|
|
537
|
-
/**
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
|
|
581
|
-
*
|
|
582
|
-
* Find the start and end location of every word with exactly 13 Unicode
|
|
583
|
-
* word characters:
|
|
584
|
-
*
|
|
585
|
-
* ```typescript
|
|
586
|
-
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
587
|
-
* const matches = new Regex("\\b\\w{13}\\b").findAll(text)
|
|
588
|
-
* ```
|
|
589
|
-
*
|
|
590
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
591
|
-
* @param {string} text - The string against which to match the regular expression
|
|
592
|
-
* @returns {Match}
|
|
593
|
-
*/
|
|
594
|
-
findAll(text: string): Match[];
|
|
595
|
-
/**
|
|
596
|
-
* Returns a list of the capture names in this regex.
|
|
597
|
-
*
|
|
598
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
599
|
-
*/
|
|
600
|
-
captureNames(): (string | null)[];
|
|
601
|
-
/**
|
|
602
|
-
* Returns the capture groups corresponding to the leftmost-first
|
|
603
|
-
* match in `text`. Capture group `0` always corresponds to the entire
|
|
604
|
-
* match. If no match is found, then `undefined` is returned.
|
|
605
|
-
*
|
|
606
|
-
* You should only use `captures` if you need access to the location of
|
|
607
|
-
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
608
|
-
* the location of the overall match.
|
|
609
|
-
*
|
|
610
|
-
* # Examples
|
|
611
|
-
*
|
|
612
|
-
* Say you have some text with movie names and their release years,
|
|
613
|
-
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
614
|
-
* looking like that, while also extracting the movie name and its release
|
|
615
|
-
* year separately.
|
|
616
|
-
*
|
|
617
|
-
* ```typescript
|
|
618
|
-
* const re = new Regex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
619
|
-
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
620
|
-
* const caps = re.captures(text)
|
|
621
|
-
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
622
|
-
* expect(caps.get[2].value).toBe("1941")
|
|
623
|
-
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
624
|
-
* ```
|
|
625
|
-
*
|
|
626
|
-
* Note that the full match is at capture group `0`. Each subsequent
|
|
627
|
-
* capture group is indexed by the order of its opening `(`.
|
|
628
|
-
*
|
|
629
|
-
* We can make this example a bit clearer by using *named* capture groups:
|
|
630
|
-
*
|
|
631
|
-
* ```typescript
|
|
632
|
-
* const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
633
|
-
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
634
|
-
* const caps = re.captures(text)
|
|
635
|
-
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
636
|
-
* expect(caps.name["year"].value).toBe("1941")
|
|
637
|
-
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
638
|
-
* ```
|
|
639
|
-
*
|
|
640
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
641
|
-
* @param {string} text - The string against which to match the regular expression
|
|
642
|
-
* @returns {Captures|undefined}
|
|
643
|
-
*/
|
|
644
|
-
captures(text: string): Captures | undefined;
|
|
645
|
-
/**
|
|
646
|
-
* Returns a list with all the non-overlapping capture groups matched
|
|
647
|
-
* in `text`. This is operationally the same as `findAll`, except it
|
|
648
|
-
* returns information about capturing group matches.
|
|
649
|
-
*
|
|
650
|
-
* # Example
|
|
651
|
-
*
|
|
652
|
-
* We can use this to find all movie titles and their release years in
|
|
653
|
-
* some text, where the movie is formatted like "'Title' (xxxx)":
|
|
654
|
-
*
|
|
655
|
-
* ```typescript
|
|
656
|
-
* const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
|
|
657
|
-
* const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
|
|
658
|
-
* for caps of re.captures_iter(text) {
|
|
659
|
-
* console.log(
|
|
660
|
-
* "Movie:", caps.name["title"].value, ","
|
|
661
|
-
* "Released:", caps.name["year"].value
|
|
662
|
-
* );
|
|
663
|
-
* }
|
|
664
|
-
* // Output:
|
|
665
|
-
* // Movie: Citizen Kane, Released: 1941
|
|
666
|
-
* // Movie: The Wizard of Oz, Released: 1939
|
|
667
|
-
* // Movie: M, Released: 1931
|
|
668
|
-
* ```
|
|
669
|
-
*
|
|
670
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
|
|
671
|
-
* @param {string} text - The string against which to match the regular expression
|
|
672
|
-
* @returns {Captures[]}
|
|
673
|
-
*/
|
|
504
|
+
/**
|
|
505
|
+
* Replaces all non-overlapping matches in `text` with the replacement
|
|
506
|
+
* provided. This is the same as calling `replacen` with `limit` set to
|
|
507
|
+
* `0`.
|
|
508
|
+
*
|
|
509
|
+
* See the documentation for `replace` for details on how to access
|
|
510
|
+
* capturing group matches in the replacement string.
|
|
511
|
+
*
|
|
512
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
513
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
514
|
+
* @param {string} text - The string against which to match the regular expression
|
|
515
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
516
|
+
* @returns {string}
|
|
517
|
+
*/
|
|
518
|
+
replaceAll(text: string, rep: string): string;
|
|
519
|
+
/**
|
|
520
|
+
* Returns a list with all the non-overlapping capture groups matched
|
|
521
|
+
* in `text`. This is operationally the same as `findAll`, except it
|
|
522
|
+
* returns information about capturing group matches.
|
|
523
|
+
*
|
|
524
|
+
* # Example
|
|
525
|
+
*
|
|
526
|
+
* We can use this to find all movie titles and their release years in
|
|
527
|
+
* some text, where the movie is formatted like "'Title' (xxxx)":
|
|
528
|
+
*
|
|
529
|
+
* ```typescript
|
|
530
|
+
* const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
|
|
531
|
+
* const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
|
|
532
|
+
* for caps of re.captures_iter(text) {
|
|
533
|
+
* console.log(
|
|
534
|
+
* "Movie:", caps.name["title"].value, ","
|
|
535
|
+
* "Released:", caps.name["year"].value
|
|
536
|
+
* );
|
|
537
|
+
* }
|
|
538
|
+
* // Output:
|
|
539
|
+
* // Movie: Citizen Kane, Released: 1941
|
|
540
|
+
* // Movie: The Wizard of Oz, Released: 1939
|
|
541
|
+
* // Movie: M, Released: 1931
|
|
542
|
+
* ```
|
|
543
|
+
*
|
|
544
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
|
|
545
|
+
* @param {string} text - The string against which to match the regular expression
|
|
546
|
+
* @returns {Captures[]}
|
|
547
|
+
*/
|
|
674
548
|
capturesAll(text: string): Captures[];
|
|
675
|
-
/**
|
|
676
|
-
* Returns the number of captures.
|
|
677
|
-
*
|
|
678
|
-
* This includes all named and unnamed groups, including the implicit
|
|
679
|
-
* unnamed group that is always present and corresponds to the entire match.
|
|
680
|
-
*
|
|
681
|
-
* Since the implicit unnamed group is always included in this length, the
|
|
682
|
-
* length returned is guaranteed to be greater than zero.
|
|
683
|
-
*
|
|
684
|
-
* ## Example
|
|
685
|
-
*
|
|
686
|
-
* ```typescript
|
|
687
|
-
* const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
|
|
688
|
-
* expect(re1.capturesLength()).toEqual(4)
|
|
689
|
-
*
|
|
690
|
-
* const re2 = new RRegex("foo")
|
|
691
|
-
* expect(re2.capturesLength()).toEqual(1)
|
|
692
|
-
*
|
|
693
|
-
* const re3 = new RRegex("(foo)")
|
|
694
|
-
* expect(re3.capturesLength()).toEqual(2)
|
|
695
|
-
*
|
|
696
|
-
* const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
|
|
697
|
-
* expect(re4.capturesLength()).toEqual(5)
|
|
698
|
-
*
|
|
699
|
-
* const re5 = new RRegex("[a&&b]")
|
|
700
|
-
* expect(re5.capturesLength()).toEqual(1)
|
|
701
|
-
* ```
|
|
702
|
-
*
|
|
703
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
|
|
704
|
-
|
|
705
|
-
*/
|
|
549
|
+
/**
|
|
550
|
+
* Returns the number of captures.
|
|
551
|
+
*
|
|
552
|
+
* This includes all named and unnamed groups, including the implicit
|
|
553
|
+
* unnamed group that is always present and corresponds to the entire match.
|
|
554
|
+
*
|
|
555
|
+
* Since the implicit unnamed group is always included in this length, the
|
|
556
|
+
* length returned is guaranteed to be greater than zero.
|
|
557
|
+
*
|
|
558
|
+
* ## Example
|
|
559
|
+
*
|
|
560
|
+
* ```typescript
|
|
561
|
+
* const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
|
|
562
|
+
* expect(re1.capturesLength()).toEqual(4)
|
|
563
|
+
*
|
|
564
|
+
* const re2 = new RRegex("foo")
|
|
565
|
+
* expect(re2.capturesLength()).toEqual(1)
|
|
566
|
+
*
|
|
567
|
+
* const re3 = new RRegex("(foo)")
|
|
568
|
+
* expect(re3.capturesLength()).toEqual(2)
|
|
569
|
+
*
|
|
570
|
+
* const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
|
|
571
|
+
* expect(re4.capturesLength()).toEqual(5)
|
|
572
|
+
*
|
|
573
|
+
* const re5 = new RRegex("[a&&b]")
|
|
574
|
+
* expect(re5.capturesLength()).toEqual(1)
|
|
575
|
+
* ```
|
|
576
|
+
*
|
|
577
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
|
|
578
|
+
*/
|
|
706
579
|
capturesLength(): number;
|
|
707
|
-
/**
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
*
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
*
|
|
722
|
-
*
|
|
723
|
-
*
|
|
724
|
-
*
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
*
|
|
728
|
-
*
|
|
729
|
-
*
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
*
|
|
739
|
-
*
|
|
740
|
-
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
|
|
744
|
-
* Here's the example using this expansion technique with named capture
|
|
745
|
-
* groups:
|
|
746
|
-
*
|
|
747
|
-
* ```typescript
|
|
748
|
-
* const re = new Regex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
|
|
749
|
-
* const result = re.replace("Springsteen, Bruce", "$first $last")
|
|
750
|
-
* expect(result).toBe("Bruce Springsteen")
|
|
751
|
-
* ```
|
|
752
|
-
*
|
|
753
|
-
* Note that using `$2` instead of `$first` or `$1` instead of `$last`
|
|
754
|
-
* would produce the same result. To write a literal `$` use `$$`.
|
|
755
|
-
*
|
|
756
|
-
* Sometimes the replacement string requires use of curly braces to
|
|
757
|
-
* delineate a capture group replacement and surrounding literal text.
|
|
758
|
-
* For example, if we wanted to join two words together with an
|
|
759
|
-
* underscore:
|
|
760
|
-
*
|
|
761
|
-
* ```typescript
|
|
762
|
-
* const re = new Regex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
|
|
763
|
-
* const result = re.replace("deep fried", "${first}_$second")
|
|
764
|
-
* expect(result).toBe("deep_fried")
|
|
765
|
-
* ```
|
|
766
|
-
*
|
|
767
|
-
* Without the curly braces, the capture group name `first_` would be
|
|
768
|
-
* used, and since it doesn't exist, it would be replaced with the empty
|
|
769
|
-
* string.
|
|
770
|
-
*
|
|
771
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
772
|
-
* @param {string} text - The string against which to match the regular expression
|
|
773
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
774
|
-
* @returns {string}
|
|
775
|
-
*/
|
|
776
|
-
replace(text: string, rep: string): string;
|
|
777
|
-
/**
|
|
778
|
-
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
779
|
-
* replacement provided. If `limit` is 0, then all non-overlapping matches
|
|
780
|
-
* are replaced.
|
|
781
|
-
*
|
|
782
|
-
* See the documentation for `replace` for details on how to access
|
|
783
|
-
* capturing group matches in the replacement string.
|
|
784
|
-
*
|
|
785
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
786
|
-
* @param {string} text - The string against which to match the regular expression
|
|
787
|
-
* @param {number} limit - Max number of replacement
|
|
788
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
789
|
-
* @returns {string}
|
|
790
|
-
*/
|
|
791
|
-
replacen(text: string, limit: number, rep: string): string;
|
|
792
|
-
/**
|
|
793
|
-
* Replaces all non-overlapping matches in `text` with the replacement
|
|
794
|
-
* provided. This is the same as calling `replacen` with `limit` set to
|
|
795
|
-
* `0`.
|
|
796
|
-
*
|
|
797
|
-
* See the documentation for `replace` for details on how to access
|
|
798
|
-
* capturing group matches in the replacement string.
|
|
799
|
-
*
|
|
800
|
-
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
801
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
802
|
-
* @param {string} text - The string against which to match the regular expression
|
|
803
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
804
|
-
* @returns {string}
|
|
805
|
-
*/
|
|
806
|
-
replaceAll(text: string, rep: string): string;
|
|
807
|
-
/**
|
|
808
|
-
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
809
|
-
* regular expression. Namely, each element of the iterator corresponds to
|
|
810
|
-
* text that *isn't* matched by the regular expression.
|
|
811
|
-
*
|
|
812
|
-
* This method will *not* copy the text given.
|
|
813
|
-
*
|
|
814
|
-
* # Example
|
|
815
|
-
*
|
|
816
|
-
* To split a string delimited by arbitrary amounts of spaces or tabs:
|
|
817
|
-
*
|
|
818
|
-
* ```typescript
|
|
819
|
-
* const re = new Regex(r"[ \\t]+")
|
|
820
|
-
* const fields = re.split("a b \t c\td e")
|
|
821
|
-
* expect(fields).toEqual(["a", "b", "c", "d", "e"])
|
|
822
|
-
* ```
|
|
823
|
-
*
|
|
824
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
825
|
-
* @param {string} text - The string against which to match the regular expression
|
|
826
|
-
* @returns {string[]}
|
|
827
|
-
*/
|
|
828
|
-
split(text: string): (string)[];
|
|
829
|
-
/**
|
|
830
|
-
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
831
|
-
* by a match of the regular expression. (A `limit` of `0` will return no
|
|
832
|
-
* substrings.) Namely, each element of the iterator corresponds to text
|
|
833
|
-
* that *isn't* matched by the regular expression. The remainder of the
|
|
834
|
-
* string that is not split will be the last element in the iterator.
|
|
835
|
-
*
|
|
836
|
-
* This method will *not* copy the text given.
|
|
837
|
-
*
|
|
838
|
-
* # Example
|
|
839
|
-
*
|
|
840
|
-
* Get the first two words in some text:
|
|
841
|
-
*
|
|
842
|
-
* ```typescript
|
|
843
|
-
* const re = new Regex(r"\\W+")
|
|
844
|
-
* const fields = re.splitn("Hey! How are you?", 3)
|
|
845
|
-
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
846
|
-
* ```
|
|
847
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
848
|
-
* @param {string} text - The string against which to match the regular expression
|
|
849
|
-
* @param {number} limit - Max number result elements
|
|
850
|
-
* @returns {string[]}
|
|
851
|
-
*/
|
|
852
|
-
splitn(text: string, limit: number): (string)[];
|
|
853
|
-
/**
|
|
854
|
-
* Returns the end location of a match in the text given.
|
|
855
|
-
*
|
|
856
|
-
* This method may have the same performance characteristics as
|
|
857
|
-
* `isMatch`, except it provides an end location for a match. In
|
|
858
|
-
* particular, the location returned *may be shorter* than the proper end
|
|
859
|
-
* of the leftmost-first match that you would find via `Regex.find`.
|
|
860
|
-
*
|
|
861
|
-
* Note that it is not guaranteed that this routine finds the shortest or
|
|
862
|
-
* "earliest" possible match. Instead, the main idea of this API is that
|
|
863
|
-
* it returns the offset at the point at which the internal regex engine
|
|
864
|
-
* has determined that a match has occurred. This may vary depending on
|
|
865
|
-
* which internal regex engine is used, and thus, the offset itself may
|
|
866
|
-
* change.
|
|
867
|
-
*
|
|
868
|
-
* # Example
|
|
869
|
-
*
|
|
870
|
-
* Typically, `a+` would match the entire first sequence of `a` in some
|
|
871
|
-
* text, but `shortest_match` can give up as soon as it sees the first
|
|
872
|
-
* `a`.
|
|
873
|
-
*
|
|
874
|
-
* ```typescript
|
|
875
|
-
* const text = "aaaaa"
|
|
876
|
-
* const = new Regex("a+").shortest_match(text)
|
|
877
|
-
* expect(pos).toBe(1)
|
|
878
|
-
* ```
|
|
879
|
-
*
|
|
880
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
881
|
-
* @param {string} text - The string against which to match the regular expression
|
|
882
|
-
* @returns {number|undefined}
|
|
883
|
-
*/
|
|
580
|
+
/**
|
|
581
|
+
* Returns a list of the capture names in this regex.
|
|
582
|
+
*
|
|
583
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
584
|
+
*/
|
|
585
|
+
captureNames(): (string | null)[];
|
|
586
|
+
/**
|
|
587
|
+
* Returns the end location of a match in the text given.
|
|
588
|
+
*
|
|
589
|
+
* This method may have the same performance characteristics as
|
|
590
|
+
* `isMatch`, except it provides an end location for a match. In
|
|
591
|
+
* particular, the location returned *may be shorter* than the proper end
|
|
592
|
+
* of the leftmost-first match that you would find via `Regex.find`.
|
|
593
|
+
*
|
|
594
|
+
* Note that it is not guaranteed that this routine finds the shortest or
|
|
595
|
+
* "earliest" possible match. Instead, the main idea of this API is that
|
|
596
|
+
* it returns the offset at the point at which the internal regex engine
|
|
597
|
+
* has determined that a match has occurred. This may vary depending on
|
|
598
|
+
* which internal regex engine is used, and thus, the offset itself may
|
|
599
|
+
* change.
|
|
600
|
+
*
|
|
601
|
+
* # Example
|
|
602
|
+
*
|
|
603
|
+
* Typically, `a+` would match the entire first sequence of `a` in some
|
|
604
|
+
* text, but `shortest_match` can give up as soon as it sees the first
|
|
605
|
+
* `a`.
|
|
606
|
+
*
|
|
607
|
+
* ```typescript
|
|
608
|
+
* const text = "aaaaa"
|
|
609
|
+
* const = new Regex("a+").shortest_match(text)
|
|
610
|
+
* expect(pos).toBe(1)
|
|
611
|
+
* ```
|
|
612
|
+
*
|
|
613
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
614
|
+
* @param {string} text - The string against which to match the regular expression
|
|
615
|
+
* @returns {number|undefined}
|
|
616
|
+
*/
|
|
884
617
|
shortestMatch(text: string): number | undefined;
|
|
885
|
-
/**
|
|
886
|
-
* Returns the same as `shortest_match`, but starts the search at the
|
|
887
|
-
* given offset.
|
|
888
|
-
*
|
|
889
|
-
* The significance of the starting point is that it takes the surrounding
|
|
890
|
-
* context into consideration. For example, the `\A` anchor can only match
|
|
891
|
-
* when `start == 0`.
|
|
892
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
893
|
-
* @param {string} text - The string against which to match the regular expression
|
|
894
|
-
* @param {number} start - Zero-based index at which to start matching
|
|
895
|
-
* @returns {number|undefined}
|
|
896
|
-
*/
|
|
618
|
+
/**
|
|
619
|
+
* Returns the same as `shortest_match`, but starts the search at the
|
|
620
|
+
* given offset.
|
|
621
|
+
*
|
|
622
|
+
* The significance of the starting point is that it takes the surrounding
|
|
623
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
624
|
+
* when `start == 0`.
|
|
625
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
626
|
+
* @param {string} text - The string against which to match the regular expression
|
|
627
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
628
|
+
* @returns {number|undefined}
|
|
629
|
+
*/
|
|
897
630
|
shortestMatchAt(text: string, start: number): number | undefined;
|
|
898
|
-
/**
|
|
899
|
-
*
|
|
900
|
-
*
|
|
901
|
-
*
|
|
902
|
-
|
|
631
|
+
/**
|
|
632
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
633
|
+
* to search, split or replace text in a string.
|
|
634
|
+
*
|
|
635
|
+
* If an invalid expression is given, then an error is returned.
|
|
636
|
+
*/
|
|
637
|
+
constructor(re: string);
|
|
638
|
+
/**
|
|
639
|
+
* Returns the start and end byte range of the leftmost-first match in
|
|
640
|
+
* `text`. If no match exists, then `undefined` is returned.
|
|
641
|
+
*
|
|
642
|
+
* Note that this should only be used if you want to discover the position
|
|
643
|
+
* of the match. Testing the existence of a match is faster if you use
|
|
644
|
+
* `isMatch`.
|
|
645
|
+
*
|
|
646
|
+
* # Example
|
|
647
|
+
*
|
|
648
|
+
* Find the start and end location of the first word with exactly 13
|
|
649
|
+
* Unicode word characters:
|
|
650
|
+
*
|
|
651
|
+
* ```typescript
|
|
652
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
653
|
+
* const m = new Regex("\\b\\w{13}\\b").find(text)
|
|
654
|
+
* expect(m.start).toBe(2)
|
|
655
|
+
* expect(m.end).toBe(15)
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
659
|
+
* @param {string} text - The string against which to match the regular expression
|
|
660
|
+
* @return {Match}
|
|
661
|
+
*/
|
|
662
|
+
find(text: string): Match | undefined;
|
|
663
|
+
/**
|
|
664
|
+
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
665
|
+
* regular expression. Namely, each element of the iterator corresponds to
|
|
666
|
+
* text that *isn't* matched by the regular expression.
|
|
667
|
+
*
|
|
668
|
+
* This method will *not* copy the text given.
|
|
669
|
+
*
|
|
670
|
+
* # Example
|
|
671
|
+
*
|
|
672
|
+
* To split a string delimited by arbitrary amounts of spaces or tabs:
|
|
673
|
+
*
|
|
674
|
+
* ```typescript
|
|
675
|
+
* const re = new Regex(r"[ \\t]+")
|
|
676
|
+
* const fields = re.split("a b \t c\td e")
|
|
677
|
+
* expect(fields).toEqual(["a", "b", "c", "d", "e"])
|
|
678
|
+
* ```
|
|
679
|
+
*
|
|
680
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
681
|
+
* @param {string} text - The string against which to match the regular expression
|
|
682
|
+
* @returns {string[]}
|
|
683
|
+
*/
|
|
684
|
+
split(text: string): string[];
|
|
685
|
+
/**
|
|
686
|
+
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
687
|
+
* by a match of the regular expression. (A `limit` of `0` will return no
|
|
688
|
+
* substrings.) Namely, each element of the iterator corresponds to text
|
|
689
|
+
* that *isn't* matched by the regular expression. The remainder of the
|
|
690
|
+
* string that is not split will be the last element in the iterator.
|
|
691
|
+
*
|
|
692
|
+
* This method will *not* copy the text given.
|
|
693
|
+
*
|
|
694
|
+
* # Example
|
|
695
|
+
*
|
|
696
|
+
* Get the first two words in some text:
|
|
697
|
+
*
|
|
698
|
+
* ```typescript
|
|
699
|
+
* const re = new Regex(r"\\W+")
|
|
700
|
+
* const fields = re.splitn("Hey! How are you?", 3)
|
|
701
|
+
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
702
|
+
* ```
|
|
703
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
704
|
+
* @param {string} text - The string against which to match the regular expression
|
|
705
|
+
* @param {number} limit - Max number result elements
|
|
706
|
+
* @returns {string[]}
|
|
707
|
+
*/
|
|
708
|
+
splitn(text: string, limit: number): string[];
|
|
709
|
+
/**
|
|
710
|
+
* Returns the regular expression into a high level intermediate
|
|
711
|
+
* representation.
|
|
712
|
+
*/
|
|
903
713
|
syntax(): Hir;
|
|
904
|
-
/**
|
|
905
|
-
* Returns
|
|
906
|
-
*
|
|
907
|
-
|
|
714
|
+
/**
|
|
715
|
+
* Returns the same as find, but starts the search at the given
|
|
716
|
+
* offset.
|
|
717
|
+
*
|
|
718
|
+
* The significance of the starting point is that it takes the surrounding
|
|
719
|
+
* context into consideration. For example, the `\A` anchor can only
|
|
720
|
+
* match when `start == 0`.
|
|
721
|
+
*
|
|
722
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
723
|
+
* @param {string} text - The string against which to match the regular expression
|
|
724
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
725
|
+
* @returns {Match}
|
|
726
|
+
*/
|
|
727
|
+
findAt(text: string, start: number): Match | undefined;
|
|
728
|
+
/**
|
|
729
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
730
|
+
* The replacement can be a regular string (where `$N` and `$name` are
|
|
731
|
+
* expanded to match capture groups) or a function that takes the matches'
|
|
732
|
+
* `Captures` and returns the replaced string.
|
|
733
|
+
*
|
|
734
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
735
|
+
*
|
|
736
|
+
* # Replacement string syntax
|
|
737
|
+
*
|
|
738
|
+
* All instances of `$name` in the replacement text is replaced with the
|
|
739
|
+
* corresponding capture group `name`.
|
|
740
|
+
*
|
|
741
|
+
* `name` may be an integer corresponding to the index of the
|
|
742
|
+
* capture group (counted by order of opening parenthesis where `0` is the
|
|
743
|
+
* entire match) or it can be a name (consisting of letters, digits or
|
|
744
|
+
* underscores) corresponding to a named capture group.
|
|
745
|
+
*
|
|
746
|
+
* If `name` isn't a valid capture group (whether the name doesn't exist
|
|
747
|
+
* or isn't a valid index), then it is replaced with the empty string.
|
|
748
|
+
*
|
|
749
|
+
* The longest possible name is used. e.g., `$1a` looks up the capture
|
|
750
|
+
* group named `1a` and not the capture group at index `1`. To exert more
|
|
751
|
+
* precise control over the name, use braces, e.g., `${1}a`.
|
|
752
|
+
*
|
|
753
|
+
* To write a literal `$` use `$$`.
|
|
754
|
+
*
|
|
755
|
+
* # Examples
|
|
756
|
+
*
|
|
757
|
+
* Note that this function is polymorphic with respect to the replacement.
|
|
758
|
+
* In typical usage, this can just be a normal string:
|
|
759
|
+
*
|
|
760
|
+
* ```typescript
|
|
761
|
+
* const re = new Regex("[^01]+")
|
|
762
|
+
* expect(re.replace("1078910", "").toBe("1010")
|
|
763
|
+
* ```
|
|
764
|
+
*
|
|
765
|
+
* Here's the example using this expansion technique with named capture
|
|
766
|
+
* groups:
|
|
767
|
+
*
|
|
768
|
+
* ```typescript
|
|
769
|
+
* const re = new Regex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
|
|
770
|
+
* const result = re.replace("Springsteen, Bruce", "$first $last")
|
|
771
|
+
* expect(result).toBe("Bruce Springsteen")
|
|
772
|
+
* ```
|
|
773
|
+
*
|
|
774
|
+
* Note that using `$2` instead of `$first` or `$1` instead of `$last`
|
|
775
|
+
* would produce the same result. To write a literal `$` use `$$`.
|
|
776
|
+
*
|
|
777
|
+
* Sometimes the replacement string requires use of curly braces to
|
|
778
|
+
* delineate a capture group replacement and surrounding literal text.
|
|
779
|
+
* For example, if we wanted to join two words together with an
|
|
780
|
+
* underscore:
|
|
781
|
+
*
|
|
782
|
+
* ```typescript
|
|
783
|
+
* const re = new Regex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
|
|
784
|
+
* const result = re.replace("deep fried", "${first}_$second")
|
|
785
|
+
* expect(result).toBe("deep_fried")
|
|
786
|
+
* ```
|
|
787
|
+
*
|
|
788
|
+
* Without the curly braces, the capture group name `first_` would be
|
|
789
|
+
* used, and since it doesn't exist, it would be replaced with the empty
|
|
790
|
+
* string.
|
|
791
|
+
*
|
|
792
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
793
|
+
* @param {string} text - The string against which to match the regular expression
|
|
794
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
795
|
+
* @returns {string}
|
|
796
|
+
*/
|
|
797
|
+
replace(text: string, rep: string): string;
|
|
798
|
+
/**
|
|
799
|
+
* Returns the capture groups corresponding to the leftmost-first
|
|
800
|
+
* match in `text`. Capture group `0` always corresponds to the entire
|
|
801
|
+
* match. If no match is found, then `undefined` is returned.
|
|
802
|
+
*
|
|
803
|
+
* You should only use `captures` if you need access to the location of
|
|
804
|
+
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
805
|
+
* the location of the overall match.
|
|
806
|
+
*
|
|
807
|
+
* # Examples
|
|
808
|
+
*
|
|
809
|
+
* Say you have some text with movie names and their release years,
|
|
810
|
+
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
811
|
+
* looking like that, while also extracting the movie name and its release
|
|
812
|
+
* year separately.
|
|
813
|
+
*
|
|
814
|
+
* ```typescript
|
|
815
|
+
* const re = new Regex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
816
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
817
|
+
* const caps = re.captures(text)
|
|
818
|
+
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
819
|
+
* expect(caps.get[2].value).toBe("1941")
|
|
820
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
821
|
+
* ```
|
|
822
|
+
*
|
|
823
|
+
* Note that the full match is at capture group `0`. Each subsequent
|
|
824
|
+
* capture group is indexed by the order of its opening `(`.
|
|
825
|
+
*
|
|
826
|
+
* We can make this example a bit clearer by using *named* capture groups:
|
|
827
|
+
*
|
|
828
|
+
* ```typescript
|
|
829
|
+
* const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
830
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
831
|
+
* const caps = re.captures(text)
|
|
832
|
+
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
833
|
+
* expect(caps.name["year"].value).toBe("1941")
|
|
834
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
835
|
+
* ```
|
|
836
|
+
*
|
|
837
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
838
|
+
* @param {string} text - The string against which to match the regular expression
|
|
839
|
+
* @returns {Captures|undefined}
|
|
840
|
+
*/
|
|
841
|
+
captures(text: string): Captures | undefined;
|
|
842
|
+
/**
|
|
843
|
+
* Returns an array for each successive non-overlapping match in `text``,
|
|
844
|
+
* returning the start and end byte indices with respect to `text`.
|
|
845
|
+
*
|
|
846
|
+
* # Example
|
|
847
|
+
*
|
|
848
|
+
* Find the start and end location of every word with exactly 13 Unicode
|
|
849
|
+
* word characters:
|
|
850
|
+
*
|
|
851
|
+
* ```typescript
|
|
852
|
+
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
853
|
+
* const matches = new Regex("\\b\\w{13}\\b").findAll(text)
|
|
854
|
+
* ```
|
|
855
|
+
*
|
|
856
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
857
|
+
* @param {string} text - The string against which to match the regular expression
|
|
858
|
+
* @returns {Match}
|
|
859
|
+
*/
|
|
860
|
+
findAll(text: string): Match[];
|
|
861
|
+
/**
|
|
862
|
+
* Returns true if and only if there is a match for the regex in the
|
|
863
|
+
* string given.
|
|
864
|
+
*
|
|
865
|
+
* It is recommended to use this method if all you need to do is test
|
|
866
|
+
* a match, since the underlying matching engine may be able to do less
|
|
867
|
+
* work.
|
|
868
|
+
*
|
|
869
|
+
* # Example
|
|
870
|
+
*
|
|
871
|
+
* Test if some text contains at least one word with exactly 13
|
|
872
|
+
* Unicode word characters:
|
|
873
|
+
*
|
|
874
|
+
* ```typescript
|
|
875
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
876
|
+
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
877
|
+
* ```
|
|
878
|
+
*
|
|
879
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
880
|
+
* @param {string} text - The string against which to match the regular expression
|
|
881
|
+
* @return {boolean}
|
|
882
|
+
*/
|
|
883
|
+
isMatch(text: string): boolean;
|
|
884
|
+
/**
|
|
885
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
886
|
+
* replacement provided. If `limit` is 0, then all non-overlapping matches
|
|
887
|
+
* are replaced.
|
|
888
|
+
*
|
|
889
|
+
* See the documentation for `replace` for details on how to access
|
|
890
|
+
* capturing group matches in the replacement string.
|
|
891
|
+
*
|
|
892
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
893
|
+
* @param {string} text - The string against which to match the regular expression
|
|
894
|
+
* @param {number} limit - Max number of replacement
|
|
895
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
896
|
+
* @returns {string}
|
|
897
|
+
*/
|
|
898
|
+
replacen(text: string, limit: number, rep: string): string;
|
|
899
|
+
/**
|
|
900
|
+
* Returns a string representing the regular expression
|
|
901
|
+
*/
|
|
908
902
|
toString(): string;
|
|
909
903
|
}
|
|
910
904
|
/**
|
|
911
|
-
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
912
|
-
* A regex set corresponds to the union of two or more regular expressions.
|
|
913
|
-
*
|
|
914
|
-
* That is, a regex set will match text where at least one of its constituent
|
|
915
|
-
* regular expressions matches. A regex set as its formulated here provides a
|
|
916
|
-
* touch more power: it will also report which regular expressions in the set match.
|
|
917
|
-
* Indeed, this is the key difference between regex sets and a single `Regex`
|
|
918
|
-
* with many alternates, since only one alternate can match at a time.
|
|
919
|
-
*
|
|
920
|
-
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
921
|
-
*/
|
|
905
|
+
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
906
|
+
* A regex set corresponds to the union of two or more regular expressions.
|
|
907
|
+
*
|
|
908
|
+
* That is, a regex set will match text where at least one of its constituent
|
|
909
|
+
* regular expressions matches. A regex set as its formulated here provides a
|
|
910
|
+
* touch more power: it will also report which regular expressions in the set match.
|
|
911
|
+
* Indeed, this is the key difference between regex sets and a single `Regex`
|
|
912
|
+
* with many alternates, since only one alternate can match at a time.
|
|
913
|
+
*
|
|
914
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
915
|
+
*/
|
|
922
916
|
export class RRegexSet {
|
|
923
917
|
free(): void;
|
|
924
|
-
/**
|
|
925
|
-
* Create a new regex set with the given regular expressions.
|
|
926
|
-
*
|
|
927
|
-
* This takes an of strings, if any item in the list is not a valid regular
|
|
928
|
-
* expressions, then an error is returned.
|
|
929
|
-
*
|
|
930
|
-
* # Example
|
|
931
|
-
*
|
|
932
|
-
* Create a new regex set from an iterator of strings:
|
|
933
|
-
*
|
|
934
|
-
* ```typescript
|
|
935
|
-
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
936
|
-
* expect(set.is_match("foo")).toBe(true)
|
|
937
|
-
* ```
|
|
938
|
-
|
|
939
|
-
*/
|
|
918
|
+
/**
|
|
919
|
+
* Create a new regex set with the given regular expressions.
|
|
920
|
+
*
|
|
921
|
+
* This takes an of strings, if any item in the list is not a valid regular
|
|
922
|
+
* expressions, then an error is returned.
|
|
923
|
+
*
|
|
924
|
+
* # Example
|
|
925
|
+
*
|
|
926
|
+
* Create a new regex set from an iterator of strings:
|
|
927
|
+
*
|
|
928
|
+
* ```typescript
|
|
929
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
930
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
931
|
+
* ```
|
|
932
|
+
*/
|
|
940
933
|
constructor(list: Array<any>);
|
|
941
|
-
/**
|
|
942
|
-
* Returns
|
|
943
|
-
*
|
|
944
|
-
*
|
|
945
|
-
*
|
|
946
|
-
* of
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
*
|
|
957
|
-
*
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
*
|
|
961
|
-
*
|
|
962
|
-
*
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
*
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
* The
|
|
975
|
-
*
|
|
976
|
-
|
|
977
|
-
*
|
|
978
|
-
* The set can also be used to iterate over the matched indices.
|
|
979
|
-
*
|
|
980
|
-
* Note that as with searches using `Regex`, the expression is unanchored
|
|
981
|
-
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
982
|
-
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
983
|
-
* text.
|
|
984
|
-
*
|
|
985
|
-
* # Example
|
|
986
|
-
*
|
|
987
|
-
* Tests which regular expressions match the given text:
|
|
988
|
-
*
|
|
989
|
-
* ```typescript
|
|
990
|
-
* const set = new RegexSet([
|
|
991
|
-
* "\\w+",
|
|
992
|
-
* "\\d+",
|
|
993
|
-
* "\\pL+",
|
|
994
|
-
* "foo",
|
|
995
|
-
* "bar",
|
|
996
|
-
* "barfoo",
|
|
997
|
-
* "foobar",
|
|
998
|
-
* ])
|
|
999
|
-
* const matches = set.matches("foobar")
|
|
1000
|
-
* expect(matches).toBe([0, 2, 3, 4, 6])
|
|
1001
|
-
* ```
|
|
1002
|
-
*
|
|
1003
|
-
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
|
|
1004
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1005
|
-
* @return {number[]}
|
|
1006
|
-
*/
|
|
934
|
+
/**
|
|
935
|
+
* Returns the set of regular expressions that match in the given text.
|
|
936
|
+
*
|
|
937
|
+
* The set returned contains the index of each regular expression that
|
|
938
|
+
* matches in the given text. The index is in correspondence with the
|
|
939
|
+
* order of regular expressions given to `RegexSet`'s constructor.
|
|
940
|
+
*
|
|
941
|
+
* The set can also be used to iterate over the matched indices.
|
|
942
|
+
*
|
|
943
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
944
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
945
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
946
|
+
* text.
|
|
947
|
+
*
|
|
948
|
+
* # Example
|
|
949
|
+
*
|
|
950
|
+
* Tests which regular expressions match the given text:
|
|
951
|
+
*
|
|
952
|
+
* ```typescript
|
|
953
|
+
* const set = new RegexSet([
|
|
954
|
+
* "\\w+",
|
|
955
|
+
* "\\d+",
|
|
956
|
+
* "\\pL+",
|
|
957
|
+
* "foo",
|
|
958
|
+
* "bar",
|
|
959
|
+
* "barfoo",
|
|
960
|
+
* "foobar",
|
|
961
|
+
* ])
|
|
962
|
+
* const matches = set.matches("foobar")
|
|
963
|
+
* expect(matches).toBe([0, 2, 3, 4, 6])
|
|
964
|
+
* ```
|
|
965
|
+
*
|
|
966
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
|
|
967
|
+
* @param {string} text - The string against which to match the regular expression
|
|
968
|
+
* @return {number[]}
|
|
969
|
+
*/
|
|
1007
970
|
matches(text: string): number[];
|
|
971
|
+
/**
|
|
972
|
+
* Returns true if and only if one of the regexes in this set matches
|
|
973
|
+
* the text given.
|
|
974
|
+
*
|
|
975
|
+
* This method should be preferred if you only need to test whether any
|
|
976
|
+
* of the regexes in the set should match, but don't care about *which*
|
|
977
|
+
* regexes matched. This is because the underlying matching engine will
|
|
978
|
+
* quit immediately after seeing the first match instead of continuing to
|
|
979
|
+
* find all matches.
|
|
980
|
+
*
|
|
981
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
982
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
983
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
984
|
+
* text.
|
|
985
|
+
*
|
|
986
|
+
* # Example
|
|
987
|
+
*
|
|
988
|
+
* Tests whether a set matches some text:
|
|
989
|
+
*
|
|
990
|
+
* ```typescript
|
|
991
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
992
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
993
|
+
* expect(!set.is_match("☃")).toBe(false)
|
|
994
|
+
* ```
|
|
995
|
+
*
|
|
996
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
997
|
+
* @param {string} text - The string against which to match the regular expression
|
|
998
|
+
* @return {boolean}
|
|
999
|
+
*/
|
|
1000
|
+
isMatch(text: string): boolean;
|
|
1008
1001
|
}
|
|
1009
1002
|
|
|
1010
1003
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
1011
1004
|
|
|
1012
1005
|
export interface InitOutput {
|
|
1013
1006
|
readonly memory: WebAssembly.Memory;
|
|
1014
|
-
readonly
|
|
1015
|
-
readonly
|
|
1007
|
+
readonly __wbg_rregexset_free: (a: number, b: number) => void;
|
|
1008
|
+
readonly rregexset_isMatch: (a: number, b: number, c: number) => number;
|
|
1009
|
+
readonly rregexset_matches: (a: number, b: number, c: number) => [number, number];
|
|
1010
|
+
readonly rregexset_new: (a: any) => [number, number, number];
|
|
1011
|
+
readonly escape: (a: number, b: number) => [number, number];
|
|
1012
|
+
readonly __wbg_rregex_free: (a: number, b: number) => void;
|
|
1013
|
+
readonly rregex_captureNames: (a: number) => [number, number];
|
|
1014
|
+
readonly rregex_captures: (a: number, b: number, c: number) => [number, number, number];
|
|
1015
|
+
readonly rregex_capturesAll: (a: number, b: number, c: number) => [number, number, number];
|
|
1016
|
+
readonly rregex_capturesLength: (a: number) => number;
|
|
1017
|
+
readonly rregex_find: (a: number, b: number, c: number) => [number, number, number];
|
|
1018
|
+
readonly rregex_findAll: (a: number, b: number, c: number) => [number, number, number];
|
|
1019
|
+
readonly rregex_findAt: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
1016
1020
|
readonly rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
1017
1021
|
readonly rregex_isMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1018
|
-
readonly
|
|
1019
|
-
readonly
|
|
1020
|
-
readonly
|
|
1021
|
-
readonly
|
|
1022
|
-
readonly
|
|
1023
|
-
readonly
|
|
1024
|
-
readonly
|
|
1025
|
-
readonly
|
|
1026
|
-
readonly
|
|
1027
|
-
readonly
|
|
1028
|
-
readonly
|
|
1029
|
-
readonly
|
|
1030
|
-
readonly
|
|
1031
|
-
readonly rregex_shortestMatchAt: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
1032
|
-
readonly rregex_syntax: (a: number, b: number) => void;
|
|
1033
|
-
readonly rregex_toString: (a: number, b: number) => void;
|
|
1034
|
-
readonly escape: (a: number, b: number, c: number) => void;
|
|
1035
|
-
readonly __wbg_rregexset_free: (a: number) => void;
|
|
1036
|
-
readonly rregexset_new: (a: number, b: number) => void;
|
|
1037
|
-
readonly rregexset_isMatch: (a: number, b: number, c: number) => number;
|
|
1038
|
-
readonly rregexset_matches: (a: number, b: number, c: number, d: number) => void;
|
|
1022
|
+
readonly rregex_new: (a: number, b: number) => [number, number, number];
|
|
1023
|
+
readonly rregex_replace: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
1024
|
+
readonly rregex_replaceAll: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
1025
|
+
readonly rregex_replacen: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
1026
|
+
readonly rregex_shortestMatch: (a: number, b: number, c: number) => number;
|
|
1027
|
+
readonly rregex_shortestMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1028
|
+
readonly rregex_split: (a: number, b: number, c: number) => [number, number];
|
|
1029
|
+
readonly rregex_splitn: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1030
|
+
readonly rregex_syntax: (a: number) => [number, number, number];
|
|
1031
|
+
readonly rregex_toString: (a: number) => [number, number];
|
|
1032
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
1033
|
+
readonly __externref_table_alloc: () => number;
|
|
1034
|
+
readonly __wbindgen_export_2: WebAssembly.Table;
|
|
1039
1035
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
1040
1036
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
1041
|
-
readonly
|
|
1037
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
1038
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
1042
1039
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
1043
|
-
readonly
|
|
1040
|
+
readonly __wbindgen_start: () => void;
|
|
1044
1041
|
}
|
|
1045
1042
|
|
|
1046
1043
|
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
@@ -1048,22 +1045,23 @@ export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
|
1048
1045
|
* Instantiates the given `module`, which can either be bytes or
|
|
1049
1046
|
* a precompiled `WebAssembly.Module`.
|
|
1050
1047
|
*
|
|
1051
|
-
* @param {SyncInitInput} module
|
|
1048
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
1052
1049
|
*
|
|
1053
1050
|
* @returns {InitOutput}
|
|
1054
1051
|
*/
|
|
1055
|
-
export function initSync(module: SyncInitInput): InitOutput;
|
|
1052
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
1056
1053
|
|
|
1057
1054
|
/**
|
|
1058
1055
|
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
1059
1056
|
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
1060
1057
|
*
|
|
1061
|
-
* @param {InitInput | Promise<InitInput>} module_or_path
|
|
1058
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
1062
1059
|
*
|
|
1063
1060
|
* @returns {Promise<InitOutput>}
|
|
1064
1061
|
*/
|
|
1065
|
-
export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
1062
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
1066
1063
|
|
|
1064
|
+
/** Build metadata */
|
|
1067
1065
|
export const metadata: {
|
|
1068
1066
|
"name": "rregex",
|
|
1069
1067
|
"description": "Rust Regex binding for Javascript",
|
|
@@ -1073,5 +1071,5 @@ export const metadata: {
|
|
|
1073
1071
|
"homepage": "http://rregex.dev",
|
|
1074
1072
|
"repository": "https://github.com/2fd/rregex",
|
|
1075
1073
|
"regex": "1.8.4",
|
|
1076
|
-
"regex-syntax": "0.7.
|
|
1074
|
+
"regex-syntax": "0.7.2"
|
|
1077
1075
|
}
|