rregex 1.10.12 → 1.10.13
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 +11 -11
- package/lib/cf.d.ts +654 -657
- package/lib/cf.mjs +1 -1
- package/lib/commonjs.cjs +792 -945
- package/lib/commonjs.d.cts +1257 -0
- package/lib/esm.d.ts +621 -628
- package/lib/esm.mjs +793 -945
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +34 -30
- package/lib/standalone.d.ts +652 -655
- package/lib/standalone.js +1011 -1148
- package/lib/types.d.ts +654 -657
- package/lib/web.d.ts +654 -657
- package/lib/web.js +820 -957
- package/package.json +37 -4
- package/lib/commonjs.d.ts +0 -1264
package/lib/standalone.d.ts
CHANGED
|
@@ -2,13 +2,11 @@ declare namespace wasm_bindgen {
|
|
|
2
2
|
/* tslint:disable */
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @returns {string}
|
|
11
|
-
*/
|
|
5
|
+
* Escapes all regular expression meta characters in `text`.
|
|
6
|
+
*
|
|
7
|
+
* The string returned may be safely used as a literal in a regular
|
|
8
|
+
* expression.
|
|
9
|
+
*/
|
|
12
10
|
export function escape(text: string): string;
|
|
13
11
|
/**
|
|
14
12
|
* Represents a single match of a regex in a haystack.
|
|
@@ -63,54 +61,6 @@ declare namespace wasm_bindgen {
|
|
|
63
61
|
value: string
|
|
64
62
|
}
|
|
65
63
|
|
|
66
|
-
/**
|
|
67
|
-
* Represents the capture groups for a single match.
|
|
68
|
-
*
|
|
69
|
-
* Capture groups refer to parts of a regex enclosed in parentheses. They can
|
|
70
|
-
* be optionally named. The purpose of capture groups is to be able to
|
|
71
|
-
* reference different parts of a match based on the original pattern. For
|
|
72
|
-
* example, say you want to match the individual letters in a 5-letter word:
|
|
73
|
-
*
|
|
74
|
-
* ```text
|
|
75
|
-
* (?<first>\w)(\w)(?:\w)\w(?<last>\w)
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* This regex has 4 capture groups:
|
|
79
|
-
*
|
|
80
|
-
* * The group at index `0` corresponds to the overall match. It is always
|
|
81
|
-
* present in every match and never has a name.
|
|
82
|
-
* * The group at index `1` with name `first` corresponding to the first
|
|
83
|
-
* letter.
|
|
84
|
-
* * The group at index `2` with no name corresponding to the second letter.
|
|
85
|
-
* * The group at index `3` with name `last` corresponding to the fifth and
|
|
86
|
-
* last letter.
|
|
87
|
-
*
|
|
88
|
-
* Notice that `(?:\w)` was not listed above as a capture group despite it
|
|
89
|
-
* being enclosed in parentheses. That's because `(?:pattern)` is a special
|
|
90
|
-
* syntax that permits grouping but *without* capturing. The reason for not
|
|
91
|
-
* treating it as a capture is that tracking and reporting capture groups
|
|
92
|
-
* requires additional state that may lead to slower searches. So using as few
|
|
93
|
-
* capture groups as possible can help performance. (Although the difference
|
|
94
|
-
* in performance of a couple of capture groups is likely immaterial.)
|
|
95
|
-
*
|
|
96
|
-
* # Example
|
|
97
|
-
*
|
|
98
|
-
* ```typescript
|
|
99
|
-
* import { RRegex } from "rregex"
|
|
100
|
-
*
|
|
101
|
-
* const re = new RRegex("(?<first>\\w)(\\w)(?:\\w)\\w(?<last>\\w)");
|
|
102
|
-
* const caps = re.captures("toady");
|
|
103
|
-
* expect(caps.get[0].value).toBe("toady");
|
|
104
|
-
* expect(caps.name["first"].value).toBe("t");
|
|
105
|
-
* expect(caps.get[2].value).toBe("o");
|
|
106
|
-
* expect(caps.name["last"].value).toBe("y");
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
export type Captures = {
|
|
110
|
-
get: Match[]
|
|
111
|
-
name: Record<string, Match>
|
|
112
|
-
}
|
|
113
|
-
|
|
114
64
|
/**
|
|
115
65
|
* A high-level intermediate representation (HIR) for a regular expression.
|
|
116
66
|
*/
|
|
@@ -636,6 +586,54 @@ declare namespace wasm_bindgen {
|
|
|
636
586
|
sub: Hir
|
|
637
587
|
}
|
|
638
588
|
|
|
589
|
+
/**
|
|
590
|
+
* Represents the capture groups for a single match.
|
|
591
|
+
*
|
|
592
|
+
* Capture groups refer to parts of a regex enclosed in parentheses. They can
|
|
593
|
+
* be optionally named. The purpose of capture groups is to be able to
|
|
594
|
+
* reference different parts of a match based on the original pattern. For
|
|
595
|
+
* example, say you want to match the individual letters in a 5-letter word:
|
|
596
|
+
*
|
|
597
|
+
* ```text
|
|
598
|
+
* (?<first>\w)(\w)(?:\w)\w(?<last>\w)
|
|
599
|
+
* ```
|
|
600
|
+
*
|
|
601
|
+
* This regex has 4 capture groups:
|
|
602
|
+
*
|
|
603
|
+
* * The group at index `0` corresponds to the overall match. It is always
|
|
604
|
+
* present in every match and never has a name.
|
|
605
|
+
* * The group at index `1` with name `first` corresponding to the first
|
|
606
|
+
* letter.
|
|
607
|
+
* * The group at index `2` with no name corresponding to the second letter.
|
|
608
|
+
* * The group at index `3` with name `last` corresponding to the fifth and
|
|
609
|
+
* last letter.
|
|
610
|
+
*
|
|
611
|
+
* Notice that `(?:\w)` was not listed above as a capture group despite it
|
|
612
|
+
* being enclosed in parentheses. That's because `(?:pattern)` is a special
|
|
613
|
+
* syntax that permits grouping but *without* capturing. The reason for not
|
|
614
|
+
* treating it as a capture is that tracking and reporting capture groups
|
|
615
|
+
* requires additional state that may lead to slower searches. So using as few
|
|
616
|
+
* capture groups as possible can help performance. (Although the difference
|
|
617
|
+
* in performance of a couple of capture groups is likely immaterial.)
|
|
618
|
+
*
|
|
619
|
+
* # Example
|
|
620
|
+
*
|
|
621
|
+
* ```typescript
|
|
622
|
+
* import { RRegex } from "rregex"
|
|
623
|
+
*
|
|
624
|
+
* const re = new RRegex("(?<first>\\w)(\\w)(?:\\w)\\w(?<last>\\w)");
|
|
625
|
+
* const caps = re.captures("toady");
|
|
626
|
+
* expect(caps.get[0].value).toBe("toady");
|
|
627
|
+
* expect(caps.name["first"].value).toBe("t");
|
|
628
|
+
* expect(caps.get[2].value).toBe("o");
|
|
629
|
+
* expect(caps.name["last"].value).toBe("y");
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
export type Captures = {
|
|
633
|
+
get: Match[]
|
|
634
|
+
name: Record<string, Match>
|
|
635
|
+
}
|
|
636
|
+
|
|
639
637
|
/**
|
|
640
638
|
* The high-level intermediate representation for a capturing group.
|
|
641
639
|
*
|
|
@@ -661,594 +659,589 @@ declare namespace wasm_bindgen {
|
|
|
661
659
|
}
|
|
662
660
|
|
|
663
661
|
/**
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
662
|
+
* A compiled regular expression for matching Unicode strings.
|
|
663
|
+
*
|
|
664
|
+
* A `RRegex` can be used to search haystacks, split haystacks into substrings
|
|
665
|
+
* or replace substrings in a haystack with a different substring. All
|
|
666
|
+
* searching is done with an implicit `(?s:.)*?` at the beginning and end of
|
|
667
|
+
* an pattern. To force an expression to match the whole string (or a prefix
|
|
668
|
+
* or a suffix), you must use an anchor like `^` or `$` (or `\A` and `\z`).
|
|
669
|
+
*
|
|
670
|
+
* While this library will handle Unicode strings (whether in the regular
|
|
671
|
+
* expression or in the haystack), all positions returned are **byte
|
|
672
|
+
* offsets**. Every byte offset is guaranteed to be at a Unicode code point
|
|
673
|
+
* boundary. That is, all offsets returned by the `RRegex` API are guaranteed
|
|
674
|
+
* to be ranges that can slice an `Uint8Array` created with a TextEncoder.
|
|
675
|
+
*
|
|
676
|
+
* # Example: slicing over UTF strings
|
|
677
|
+
*
|
|
678
|
+
* ```typescript
|
|
679
|
+
* import { RRegex } from "rregex"
|
|
680
|
+
*
|
|
681
|
+
* const re = new RRegex("ä")
|
|
682
|
+
* const m = re.find("äöü") // { start: 0, end: 2 }
|
|
683
|
+
*
|
|
684
|
+
* const buff = new TextEncoder().encode("äöü")
|
|
685
|
+
* const slice = buff.slice(m.start, m.end)
|
|
686
|
+
* expect(new TextDecoder().decode(slice)).toBe("ä")
|
|
687
|
+
* ```
|
|
688
|
+
*
|
|
689
|
+
* # Example: find the offsets of a US phone number:
|
|
690
|
+
*
|
|
691
|
+
* ```typescript
|
|
692
|
+
* import { RRegex } from "rregex"
|
|
693
|
+
*
|
|
694
|
+
* const re = new RRegex("[0-9]{3}-[0-9]{3}-[0-9]{4}");
|
|
695
|
+
* const m = re.find("phone: 111-222-3333");
|
|
696
|
+
* expect(m.start).toBe(7);
|
|
697
|
+
* expect(m.end).toBe(19);
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
* @see https://docs.rs/regex/latest/regex/
|
|
701
|
+
*/
|
|
704
702
|
export class RRegex {
|
|
705
703
|
free(): void;
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
*
|
|
718
|
-
* It is recommended to use this method if all you need to do is test
|
|
719
|
-
* a match, since the underlying matching engine may be able to do less
|
|
720
|
-
* work.
|
|
721
|
-
*
|
|
722
|
-
* # Example
|
|
723
|
-
*
|
|
724
|
-
* Test if some text contains at least one word with exactly 13
|
|
725
|
-
* Unicode word characters:
|
|
726
|
-
*
|
|
727
|
-
* ```typescript
|
|
728
|
-
* import { RRegex } from "rregex"
|
|
729
|
-
*
|
|
730
|
-
* const text = "I categorically deny having triskaidekaphobia."
|
|
731
|
-
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
732
|
-
* ```
|
|
733
|
-
*
|
|
734
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
735
|
-
* @param {string} text - The string against which to match the regular expression
|
|
736
|
-
* @return {boolean}
|
|
737
|
-
*/
|
|
738
|
-
isMatch(text: string): boolean;
|
|
739
|
-
/**
|
|
740
|
-
* Returns the same as is_match, but starts the search at the given offset.
|
|
741
|
-
* The significance of the starting point is that it takes the surrounding
|
|
742
|
-
* context into consideration. For example, the `\A` anchor can only match
|
|
743
|
-
* when `start == 0`.
|
|
744
|
-
*
|
|
745
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
746
|
-
* @param {string} text - The string against which to match the regular expression
|
|
747
|
-
* @param {number} start - Zero-based index at which to start matching
|
|
748
|
-
* @return {boolean}
|
|
749
|
-
*/
|
|
704
|
+
/**
|
|
705
|
+
* Returns the same as is_match, but starts the search at the given offset.
|
|
706
|
+
* The significance of the starting point is that it takes the surrounding
|
|
707
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
708
|
+
* when `start == 0`.
|
|
709
|
+
*
|
|
710
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
711
|
+
* @param {string} text - The string against which to match the regular expression
|
|
712
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
713
|
+
* @return {boolean}
|
|
714
|
+
*/
|
|
750
715
|
isMatchAt(text: string, start: number): boolean;
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
*
|
|
798
|
-
* Find the start and end location of every word with exactly 13 Unicode
|
|
799
|
-
* word characters:
|
|
800
|
-
*
|
|
801
|
-
* ```typescript
|
|
802
|
-
* import { RRegex } from "rregex"
|
|
803
|
-
*
|
|
804
|
-
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
805
|
-
* const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
|
|
806
|
-
* ```
|
|
807
|
-
*
|
|
808
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
809
|
-
* @param {string} text - The string against which to match the regular expression
|
|
810
|
-
* @returns {Match}
|
|
811
|
-
*/
|
|
812
|
-
findAll(text: string): Match[];
|
|
813
|
-
/**
|
|
814
|
-
* Returns a list of the capture names in this regex.
|
|
815
|
-
*
|
|
816
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
817
|
-
*/
|
|
818
|
-
captureNames(): (string | null)[];
|
|
819
|
-
/**
|
|
820
|
-
* Returns the capture groups corresponding to the leftmost-first
|
|
821
|
-
* match in `text`. Capture group `0` always corresponds to the entire
|
|
822
|
-
* match. If no match is found, then `undefined` is returned.
|
|
823
|
-
*
|
|
824
|
-
* You should only use `captures` if you need access to the location of
|
|
825
|
-
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
826
|
-
* the location of the overall match.
|
|
827
|
-
*
|
|
828
|
-
* # Examples
|
|
829
|
-
*
|
|
830
|
-
* Say you have some text with movie names and their release years,
|
|
831
|
-
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
832
|
-
* looking like that, while also extracting the movie name and its release
|
|
833
|
-
* year separately.
|
|
834
|
-
*
|
|
835
|
-
* ```typescript
|
|
836
|
-
* import { RRegex } from "rregex"
|
|
837
|
-
*
|
|
838
|
-
* const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
839
|
-
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
840
|
-
* const caps = re.captures(text)
|
|
841
|
-
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
842
|
-
* expect(caps.get[2].value).toBe("1941")
|
|
843
|
-
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
844
|
-
* ```
|
|
845
|
-
*
|
|
846
|
-
* Note that the full match is at capture group `0`. Each subsequent
|
|
847
|
-
* capture group is indexed by the order of its opening `(`.
|
|
848
|
-
*
|
|
849
|
-
* We can make this example a bit clearer by using *named* capture groups:
|
|
850
|
-
*
|
|
851
|
-
* ```typescript
|
|
852
|
-
* import { RRegex } from "rregex"
|
|
853
|
-
*
|
|
854
|
-
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
855
|
-
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
856
|
-
* const caps = re.captures(text)
|
|
857
|
-
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
858
|
-
* expect(caps.name["year"].value).toBe("1941")
|
|
859
|
-
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
860
|
-
* ```
|
|
861
|
-
*
|
|
862
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
863
|
-
* @param {string} text - The string against which to match the regular expression
|
|
864
|
-
* @returns {Captures|undefined}
|
|
865
|
-
*/
|
|
866
|
-
captures(text: string): Captures | undefined;
|
|
867
|
-
/**
|
|
868
|
-
* Returns a list with all the non-overlapping capture groups matched
|
|
869
|
-
* in `text`. This is operationally the same as `findAll`, except it
|
|
870
|
-
* returns information about capturing group matches.
|
|
871
|
-
*
|
|
872
|
-
* # Example
|
|
873
|
-
*
|
|
874
|
-
* We can use this to find all movie titles and their release years in
|
|
875
|
-
* some text, where the movie is formatted like "'Title' (xxxx)":
|
|
876
|
-
*
|
|
877
|
-
* ```typescript
|
|
878
|
-
* import { RRegex } from "rregex"
|
|
879
|
-
*
|
|
880
|
-
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
|
|
881
|
-
* const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
|
|
882
|
-
* for caps of re.captures_iter(text) {
|
|
883
|
-
* console.log(
|
|
884
|
-
* "Movie:", caps.name["title"].value, ","
|
|
885
|
-
* "Released:", caps.name["year"].value
|
|
886
|
-
* );
|
|
887
|
-
* }
|
|
888
|
-
* // Output:
|
|
889
|
-
* // Movie: Citizen Kane, Released: 1941
|
|
890
|
-
* // Movie: The Wizard of Oz, Released: 1939
|
|
891
|
-
* // Movie: M, Released: 1931
|
|
892
|
-
* ```
|
|
893
|
-
*
|
|
894
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
|
|
895
|
-
* @param {string} text - The string against which to match the regular expression
|
|
896
|
-
* @returns {Captures[]}
|
|
897
|
-
*/
|
|
716
|
+
/**
|
|
717
|
+
* Replaces all non-overlapping matches in `text` with the replacement
|
|
718
|
+
* provided. This is the same as calling `replacen` with `limit` set to
|
|
719
|
+
* `0`.
|
|
720
|
+
*
|
|
721
|
+
* See the documentation for `replace` for details on how to access
|
|
722
|
+
* capturing group matches in the replacement string.
|
|
723
|
+
*
|
|
724
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
725
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
726
|
+
* @param {string} text - The string against which to match the regular expression
|
|
727
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
728
|
+
* @returns {string}
|
|
729
|
+
*/
|
|
730
|
+
replaceAll(text: string, rep: string): string;
|
|
731
|
+
/**
|
|
732
|
+
* Returns a list with all the non-overlapping capture groups matched
|
|
733
|
+
* in `text`. This is operationally the same as `findAll`, except it
|
|
734
|
+
* returns information about capturing group matches.
|
|
735
|
+
*
|
|
736
|
+
* # Example
|
|
737
|
+
*
|
|
738
|
+
* We can use this to find all movie titles and their release years in
|
|
739
|
+
* some text, where the movie is formatted like "'Title' (xxxx)":
|
|
740
|
+
*
|
|
741
|
+
* ```typescript
|
|
742
|
+
* import { RRegex } from "rregex"
|
|
743
|
+
*
|
|
744
|
+
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
|
|
745
|
+
* const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
|
|
746
|
+
* for caps of re.captures_iter(text) {
|
|
747
|
+
* console.log(
|
|
748
|
+
* "Movie:", caps.name["title"].value, ","
|
|
749
|
+
* "Released:", caps.name["year"].value
|
|
750
|
+
* );
|
|
751
|
+
* }
|
|
752
|
+
* // Output:
|
|
753
|
+
* // Movie: Citizen Kane, Released: 1941
|
|
754
|
+
* // Movie: The Wizard of Oz, Released: 1939
|
|
755
|
+
* // Movie: M, Released: 1931
|
|
756
|
+
* ```
|
|
757
|
+
*
|
|
758
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
|
|
759
|
+
* @param {string} text - The string against which to match the regular expression
|
|
760
|
+
* @returns {Captures[]}
|
|
761
|
+
*/
|
|
898
762
|
capturesAll(text: string): Captures[];
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
*/
|
|
763
|
+
/**
|
|
764
|
+
* Returns the number of captures.
|
|
765
|
+
*
|
|
766
|
+
* This includes all named and unnamed groups, including the implicit
|
|
767
|
+
* unnamed group that is always present and corresponds to the entire match.
|
|
768
|
+
*
|
|
769
|
+
* Since the implicit unnamed group is always included in this length, the
|
|
770
|
+
* length returned is guaranteed to be greater than zero.
|
|
771
|
+
*
|
|
772
|
+
* ## Example
|
|
773
|
+
*
|
|
774
|
+
* ```typescript
|
|
775
|
+
* import { RRegex } from "rregex"
|
|
776
|
+
*
|
|
777
|
+
* const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
|
|
778
|
+
* expect(re1.capturesLength()).toEqual(4)
|
|
779
|
+
*
|
|
780
|
+
* const re2 = new RRegex("foo")
|
|
781
|
+
* expect(re2.capturesLength()).toEqual(1)
|
|
782
|
+
*
|
|
783
|
+
* const re3 = new RRegex("(foo)")
|
|
784
|
+
* expect(re3.capturesLength()).toEqual(2)
|
|
785
|
+
*
|
|
786
|
+
* const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
|
|
787
|
+
* expect(re4.capturesLength()).toEqual(5)
|
|
788
|
+
*
|
|
789
|
+
* const re5 = new RRegex("[a&&b]")
|
|
790
|
+
* expect(re5.capturesLength()).toEqual(1)
|
|
791
|
+
* ```
|
|
792
|
+
*
|
|
793
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
|
|
794
|
+
*/
|
|
932
795
|
capturesLength(): number;
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
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
|
-
* Here's the example using this expansion technique with named capture
|
|
973
|
-
* groups:
|
|
974
|
-
*
|
|
975
|
-
* ```typescript
|
|
976
|
-
* import { RRegex } from "rregex"
|
|
977
|
-
*
|
|
978
|
-
* const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
|
|
979
|
-
* const result = re.replace("Springsteen, Bruce", "$first $last")
|
|
980
|
-
* expect(result).toBe("Bruce Springsteen")
|
|
981
|
-
* ```
|
|
982
|
-
*
|
|
983
|
-
* Note that using `$2` instead of `$first` or `$1` instead of `$last`
|
|
984
|
-
* would produce the same result. To write a literal `$` use `$$`.
|
|
985
|
-
*
|
|
986
|
-
* Sometimes the replacement string requires use of curly braces to
|
|
987
|
-
* delineate a capture group replacement and surrounding literal text.
|
|
988
|
-
* For example, if we wanted to join two words together with an
|
|
989
|
-
* underscore:
|
|
990
|
-
*
|
|
991
|
-
* ```typescript
|
|
992
|
-
* import { RRegex } from "rregex"
|
|
993
|
-
*
|
|
994
|
-
* const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
|
|
995
|
-
* const result = re.replace("deep fried", "${first}_$second")
|
|
996
|
-
* expect(result).toBe("deep_fried")
|
|
997
|
-
* ```
|
|
998
|
-
*
|
|
999
|
-
* Without the curly braces, the capture group name `first_` would be
|
|
1000
|
-
* used, and since it doesn't exist, it would be replaced with the empty
|
|
1001
|
-
* string.
|
|
1002
|
-
*
|
|
1003
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
1004
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1005
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1006
|
-
* @returns {string}
|
|
1007
|
-
*/
|
|
1008
|
-
replace(text: string, rep: string): string;
|
|
1009
|
-
/**
|
|
1010
|
-
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
1011
|
-
* replacement provided. If `limit` is 0, then all non-overlapping matches
|
|
1012
|
-
* are replaced.
|
|
1013
|
-
*
|
|
1014
|
-
* See the documentation for `replace` for details on how to access
|
|
1015
|
-
* capturing group matches in the replacement string.
|
|
1016
|
-
*
|
|
1017
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
1018
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1019
|
-
* @param {number} limit - Max number of replacement
|
|
1020
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1021
|
-
* @returns {string}
|
|
1022
|
-
*/
|
|
1023
|
-
replacen(text: string, limit: number, rep: string): string;
|
|
1024
|
-
/**
|
|
1025
|
-
* Replaces all non-overlapping matches in `text` with the replacement
|
|
1026
|
-
* provided. This is the same as calling `replacen` with `limit` set to
|
|
1027
|
-
* `0`.
|
|
1028
|
-
*
|
|
1029
|
-
* See the documentation for `replace` for details on how to access
|
|
1030
|
-
* capturing group matches in the replacement string.
|
|
1031
|
-
*
|
|
1032
|
-
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
1033
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
1034
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1035
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1036
|
-
* @returns {string}
|
|
1037
|
-
*/
|
|
1038
|
-
replaceAll(text: string, rep: string): string;
|
|
1039
|
-
/**
|
|
1040
|
-
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
1041
|
-
* regular expression. Namely, each element of the iterator corresponds to
|
|
1042
|
-
* text that *isn't* matched by the regular expression.
|
|
1043
|
-
*
|
|
1044
|
-
* This method will *not* copy the text given.
|
|
1045
|
-
*
|
|
1046
|
-
* # Example
|
|
1047
|
-
*
|
|
1048
|
-
* To split a string delimited by arbitrary amounts of spaces or tabs:
|
|
1049
|
-
*
|
|
1050
|
-
* ```typescript
|
|
1051
|
-
* import { RRegex } from "rregex"
|
|
1052
|
-
*
|
|
1053
|
-
* const re = new RRegex(r"[ \\t]+")
|
|
1054
|
-
* const fields = re.split("a b \t c\td e")
|
|
1055
|
-
* expect(fields).toEqual(["a", "b", "c", "d", "e"])
|
|
1056
|
-
* ```
|
|
1057
|
-
*
|
|
1058
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
1059
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1060
|
-
* @returns {string[]}
|
|
1061
|
-
*/
|
|
1062
|
-
split(text: string): (string)[];
|
|
1063
|
-
/**
|
|
1064
|
-
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
1065
|
-
* by a match of the regular expression. (A `limit` of `0` will return no
|
|
1066
|
-
* substrings.) Namely, each element of the iterator corresponds to text
|
|
1067
|
-
* that *isn't* matched by the regular expression. The remainder of the
|
|
1068
|
-
* string that is not split will be the last element in the iterator.
|
|
1069
|
-
*
|
|
1070
|
-
* This method will *not* copy the text given.
|
|
1071
|
-
*
|
|
1072
|
-
* # Example
|
|
1073
|
-
*
|
|
1074
|
-
* Get the first two words in some text:
|
|
1075
|
-
*
|
|
1076
|
-
* ```typescript
|
|
1077
|
-
* import { RRegex } from "rregex"
|
|
1078
|
-
*
|
|
1079
|
-
* const re = new RRegex(r"\\W+")
|
|
1080
|
-
* const fields = re.splitn("Hey! How are you?", 3)
|
|
1081
|
-
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
1082
|
-
* ```
|
|
1083
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
1084
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1085
|
-
* @param {number} limit - Max number result elements
|
|
1086
|
-
* @returns {string[]}
|
|
1087
|
-
*/
|
|
1088
|
-
splitn(text: string, limit: number): (string)[];
|
|
1089
|
-
/**
|
|
1090
|
-
* Returns the end location of a match in the text given.
|
|
1091
|
-
*
|
|
1092
|
-
* This method may have the same performance characteristics as
|
|
1093
|
-
* `isMatch`, except it provides an end location for a match. In
|
|
1094
|
-
* particular, the location returned *may be shorter* than the proper end
|
|
1095
|
-
* of the leftmost-first match that you would find via `Regex.find`.
|
|
1096
|
-
*
|
|
1097
|
-
* Note that it is not guaranteed that this routine finds the shortest or
|
|
1098
|
-
* "earliest" possible match. Instead, the main idea of this API is that
|
|
1099
|
-
* it returns the offset at the point at which the internal regex engine
|
|
1100
|
-
* has determined that a match has occurred. This may vary depending on
|
|
1101
|
-
* which internal regex engine is used, and thus, the offset itself may
|
|
1102
|
-
* change.
|
|
1103
|
-
*
|
|
1104
|
-
* # Example
|
|
1105
|
-
*
|
|
1106
|
-
* Typically, `a+` would match the entire first sequence of `a` in some
|
|
1107
|
-
* text, but `shortest_match` can give up as soon as it sees the first
|
|
1108
|
-
* `a`.
|
|
1109
|
-
*
|
|
1110
|
-
* ```typescript
|
|
1111
|
-
* import { RRegex } from "rregex"
|
|
1112
|
-
*
|
|
1113
|
-
* const text = "aaaaa"
|
|
1114
|
-
* const = new RRegex("a+").shortest_match(text)
|
|
1115
|
-
* expect(pos).toBe(1)
|
|
1116
|
-
* ```
|
|
1117
|
-
*
|
|
1118
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
1119
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1120
|
-
* @returns {number|undefined}
|
|
1121
|
-
*/
|
|
796
|
+
/**
|
|
797
|
+
* Returns a list of the capture names in this regex.
|
|
798
|
+
*
|
|
799
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
800
|
+
*/
|
|
801
|
+
captureNames(): (string | null)[];
|
|
802
|
+
/**
|
|
803
|
+
* Returns the end location of a match in the text given.
|
|
804
|
+
*
|
|
805
|
+
* This method may have the same performance characteristics as
|
|
806
|
+
* `isMatch`, except it provides an end location for a match. In
|
|
807
|
+
* particular, the location returned *may be shorter* than the proper end
|
|
808
|
+
* of the leftmost-first match that you would find via `Regex.find`.
|
|
809
|
+
*
|
|
810
|
+
* Note that it is not guaranteed that this routine finds the shortest or
|
|
811
|
+
* "earliest" possible match. Instead, the main idea of this API is that
|
|
812
|
+
* it returns the offset at the point at which the internal regex engine
|
|
813
|
+
* has determined that a match has occurred. This may vary depending on
|
|
814
|
+
* which internal regex engine is used, and thus, the offset itself may
|
|
815
|
+
* change.
|
|
816
|
+
*
|
|
817
|
+
* # Example
|
|
818
|
+
*
|
|
819
|
+
* Typically, `a+` would match the entire first sequence of `a` in some
|
|
820
|
+
* text, but `shortest_match` can give up as soon as it sees the first
|
|
821
|
+
* `a`.
|
|
822
|
+
*
|
|
823
|
+
* ```typescript
|
|
824
|
+
* import { RRegex } from "rregex"
|
|
825
|
+
*
|
|
826
|
+
* const text = "aaaaa"
|
|
827
|
+
* const = new RRegex("a+").shortest_match(text)
|
|
828
|
+
* expect(pos).toBe(1)
|
|
829
|
+
* ```
|
|
830
|
+
*
|
|
831
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
832
|
+
* @param {string} text - The string against which to match the regular expression
|
|
833
|
+
* @returns {number|undefined}
|
|
834
|
+
*/
|
|
1122
835
|
shortestMatch(text: string): number | undefined;
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
836
|
+
/**
|
|
837
|
+
* Returns the same as `shortest_match`, but starts the search at the
|
|
838
|
+
* given offset.
|
|
839
|
+
*
|
|
840
|
+
* The significance of the starting point is that it takes the surrounding
|
|
841
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
842
|
+
* when `start == 0`.
|
|
843
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
844
|
+
* @param {string} text - The string against which to match the regular expression
|
|
845
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
846
|
+
* @returns {number|undefined}
|
|
847
|
+
*/
|
|
1135
848
|
shortestMatchAt(text: string, start: number): number | undefined;
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
849
|
+
/**
|
|
850
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
851
|
+
* to search, split or replace text in a string.
|
|
852
|
+
*
|
|
853
|
+
* If an invalid expression is given, then an error is returned.
|
|
854
|
+
*/
|
|
855
|
+
constructor(re: string);
|
|
856
|
+
/**
|
|
857
|
+
* Returns the start and end byte range of the leftmost-first match in
|
|
858
|
+
* `text`. If no match exists, then `undefined` is returned.
|
|
859
|
+
*
|
|
860
|
+
* Note that this should only be used if you want to discover the position
|
|
861
|
+
* of the match. Testing the existence of a match is faster if you use
|
|
862
|
+
* `isMatch`.
|
|
863
|
+
*
|
|
864
|
+
* # Example
|
|
865
|
+
*
|
|
866
|
+
* Find the start and end location of the first word with exactly 13
|
|
867
|
+
* Unicode word characters:
|
|
868
|
+
*
|
|
869
|
+
* ```typescript
|
|
870
|
+
* import { RRegex } from "rregex"
|
|
871
|
+
*
|
|
872
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
873
|
+
* const m = new RRegex("\\b\\w{13}\\b").find(text)
|
|
874
|
+
* expect(m.start).toBe(2)
|
|
875
|
+
* expect(m.end).toBe(15)
|
|
876
|
+
* ```
|
|
877
|
+
*
|
|
878
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
879
|
+
* @param {string} text - The string against which to match the regular expression
|
|
880
|
+
* @return {Match}
|
|
881
|
+
*/
|
|
882
|
+
find(text: string): Match | undefined;
|
|
883
|
+
/**
|
|
884
|
+
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
885
|
+
* regular expression. Namely, each element of the iterator corresponds to
|
|
886
|
+
* text that *isn't* matched by the regular expression.
|
|
887
|
+
*
|
|
888
|
+
* This method will *not* copy the text given.
|
|
889
|
+
*
|
|
890
|
+
* # Example
|
|
891
|
+
*
|
|
892
|
+
* To split a string delimited by arbitrary amounts of spaces or tabs:
|
|
893
|
+
*
|
|
894
|
+
* ```typescript
|
|
895
|
+
* import { RRegex } from "rregex"
|
|
896
|
+
*
|
|
897
|
+
* const re = new RRegex(r"[ \\t]+")
|
|
898
|
+
* const fields = re.split("a b \t c\td e")
|
|
899
|
+
* expect(fields).toEqual(["a", "b", "c", "d", "e"])
|
|
900
|
+
* ```
|
|
901
|
+
*
|
|
902
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
903
|
+
* @param {string} text - The string against which to match the regular expression
|
|
904
|
+
* @returns {string[]}
|
|
905
|
+
*/
|
|
906
|
+
split(text: string): string[];
|
|
907
|
+
/**
|
|
908
|
+
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
909
|
+
* by a match of the regular expression. (A `limit` of `0` will return no
|
|
910
|
+
* substrings.) Namely, each element of the iterator corresponds to text
|
|
911
|
+
* that *isn't* matched by the regular expression. The remainder of the
|
|
912
|
+
* string that is not split will be the last element in the iterator.
|
|
913
|
+
*
|
|
914
|
+
* This method will *not* copy the text given.
|
|
915
|
+
*
|
|
916
|
+
* # Example
|
|
917
|
+
*
|
|
918
|
+
* Get the first two words in some text:
|
|
919
|
+
*
|
|
920
|
+
* ```typescript
|
|
921
|
+
* import { RRegex } from "rregex"
|
|
922
|
+
*
|
|
923
|
+
* const re = new RRegex(r"\\W+")
|
|
924
|
+
* const fields = re.splitn("Hey! How are you?", 3)
|
|
925
|
+
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
926
|
+
* ```
|
|
927
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
928
|
+
* @param {string} text - The string against which to match the regular expression
|
|
929
|
+
* @param {number} limit - Max number result elements
|
|
930
|
+
* @returns {string[]}
|
|
931
|
+
*/
|
|
932
|
+
splitn(text: string, limit: number): string[];
|
|
933
|
+
/**
|
|
934
|
+
* Returns the regular expression into a high level intermediate
|
|
935
|
+
* representation.
|
|
936
|
+
*/
|
|
1141
937
|
syntax(): Hir;
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
938
|
+
/**
|
|
939
|
+
* Returns the same as find, but starts the search at the given
|
|
940
|
+
* offset.
|
|
941
|
+
*
|
|
942
|
+
* The significance of the starting point is that it takes the surrounding
|
|
943
|
+
* context into consideration. For example, the `\A` anchor can only
|
|
944
|
+
* match when `start == 0`.
|
|
945
|
+
*
|
|
946
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
947
|
+
* @param {string} text - The string against which to match the regular expression
|
|
948
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
949
|
+
* @returns {Match}
|
|
950
|
+
*/
|
|
951
|
+
findAt(text: string, start: number): Match | undefined;
|
|
952
|
+
/**
|
|
953
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
954
|
+
* The replacement can be a regular string (where `$N` and `$name` are
|
|
955
|
+
* expanded to match capture groups) or a function that takes the matches'
|
|
956
|
+
* `Captures` and returns the replaced string.
|
|
957
|
+
*
|
|
958
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
959
|
+
*
|
|
960
|
+
* # Replacement string syntax
|
|
961
|
+
*
|
|
962
|
+
* All instances of `$name` in the replacement text is replaced with the
|
|
963
|
+
* corresponding capture group `name`.
|
|
964
|
+
*
|
|
965
|
+
* `name` may be an integer corresponding to the index of the
|
|
966
|
+
* capture group (counted by order of opening parenthesis where `0` is the
|
|
967
|
+
* entire match) or it can be a name (consisting of letters, digits or
|
|
968
|
+
* underscores) corresponding to a named capture group.
|
|
969
|
+
*
|
|
970
|
+
* If `name` isn't a valid capture group (whether the name doesn't exist
|
|
971
|
+
* or isn't a valid index), then it is replaced with the empty string.
|
|
972
|
+
*
|
|
973
|
+
* The longest possible name is used. e.g., `$1a` looks up the capture
|
|
974
|
+
* group named `1a` and not the capture group at index `1`. To exert more
|
|
975
|
+
* precise control over the name, use braces, e.g., `${1}a`.
|
|
976
|
+
*
|
|
977
|
+
* To write a literal `$` use `$$`.
|
|
978
|
+
*
|
|
979
|
+
* # Examples
|
|
980
|
+
*
|
|
981
|
+
* Note that this function is polymorphic with respect to the replacement.
|
|
982
|
+
* In typical usage, this can just be a normal string:
|
|
983
|
+
*
|
|
984
|
+
* ```typescript
|
|
985
|
+
* import { RRegex } from "rregex"
|
|
986
|
+
*
|
|
987
|
+
* const re = new RRegex("[^01]+")
|
|
988
|
+
* expect(re.replace("1078910", "").toBe("1010")
|
|
989
|
+
* ```
|
|
990
|
+
*
|
|
991
|
+
* Here's the example using this expansion technique with named capture
|
|
992
|
+
* groups:
|
|
993
|
+
*
|
|
994
|
+
* ```typescript
|
|
995
|
+
* import { RRegex } from "rregex"
|
|
996
|
+
*
|
|
997
|
+
* const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
|
|
998
|
+
* const result = re.replace("Springsteen, Bruce", "$first $last")
|
|
999
|
+
* expect(result).toBe("Bruce Springsteen")
|
|
1000
|
+
* ```
|
|
1001
|
+
*
|
|
1002
|
+
* Note that using `$2` instead of `$first` or `$1` instead of `$last`
|
|
1003
|
+
* would produce the same result. To write a literal `$` use `$$`.
|
|
1004
|
+
*
|
|
1005
|
+
* Sometimes the replacement string requires use of curly braces to
|
|
1006
|
+
* delineate a capture group replacement and surrounding literal text.
|
|
1007
|
+
* For example, if we wanted to join two words together with an
|
|
1008
|
+
* underscore:
|
|
1009
|
+
*
|
|
1010
|
+
* ```typescript
|
|
1011
|
+
* import { RRegex } from "rregex"
|
|
1012
|
+
*
|
|
1013
|
+
* const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
|
|
1014
|
+
* const result = re.replace("deep fried", "${first}_$second")
|
|
1015
|
+
* expect(result).toBe("deep_fried")
|
|
1016
|
+
* ```
|
|
1017
|
+
*
|
|
1018
|
+
* Without the curly braces, the capture group name `first_` would be
|
|
1019
|
+
* used, and since it doesn't exist, it would be replaced with the empty
|
|
1020
|
+
* string.
|
|
1021
|
+
*
|
|
1022
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
1023
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1024
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1025
|
+
* @returns {string}
|
|
1026
|
+
*/
|
|
1027
|
+
replace(text: string, rep: string): string;
|
|
1028
|
+
/**
|
|
1029
|
+
* Returns the capture groups corresponding to the leftmost-first
|
|
1030
|
+
* match in `text`. Capture group `0` always corresponds to the entire
|
|
1031
|
+
* match. If no match is found, then `undefined` is returned.
|
|
1032
|
+
*
|
|
1033
|
+
* You should only use `captures` if you need access to the location of
|
|
1034
|
+
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
1035
|
+
* the location of the overall match.
|
|
1036
|
+
*
|
|
1037
|
+
* # Examples
|
|
1038
|
+
*
|
|
1039
|
+
* Say you have some text with movie names and their release years,
|
|
1040
|
+
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
1041
|
+
* looking like that, while also extracting the movie name and its release
|
|
1042
|
+
* year separately.
|
|
1043
|
+
*
|
|
1044
|
+
* ```typescript
|
|
1045
|
+
* import { RRegex } from "rregex"
|
|
1046
|
+
*
|
|
1047
|
+
* const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
1048
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
1049
|
+
* const caps = re.captures(text)
|
|
1050
|
+
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
1051
|
+
* expect(caps.get[2].value).toBe("1941")
|
|
1052
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
1053
|
+
* ```
|
|
1054
|
+
*
|
|
1055
|
+
* Note that the full match is at capture group `0`. Each subsequent
|
|
1056
|
+
* capture group is indexed by the order of its opening `(`.
|
|
1057
|
+
*
|
|
1058
|
+
* We can make this example a bit clearer by using *named* capture groups:
|
|
1059
|
+
*
|
|
1060
|
+
* ```typescript
|
|
1061
|
+
* import { RRegex } from "rregex"
|
|
1062
|
+
*
|
|
1063
|
+
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
1064
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
1065
|
+
* const caps = re.captures(text)
|
|
1066
|
+
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
1067
|
+
* expect(caps.name["year"].value).toBe("1941")
|
|
1068
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
1069
|
+
* ```
|
|
1070
|
+
*
|
|
1071
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
1072
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1073
|
+
* @returns {Captures|undefined}
|
|
1074
|
+
*/
|
|
1075
|
+
captures(text: string): Captures | undefined;
|
|
1076
|
+
/**
|
|
1077
|
+
* Returns an array for each successive non-overlapping match in `text``,
|
|
1078
|
+
* returning the start and end byte indices with respect to `text`.
|
|
1079
|
+
*
|
|
1080
|
+
* # Example
|
|
1081
|
+
*
|
|
1082
|
+
* Find the start and end location of every word with exactly 13 Unicode
|
|
1083
|
+
* word characters:
|
|
1084
|
+
*
|
|
1085
|
+
* ```typescript
|
|
1086
|
+
* import { RRegex } from "rregex"
|
|
1087
|
+
*
|
|
1088
|
+
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
1089
|
+
* const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
|
|
1090
|
+
* ```
|
|
1091
|
+
*
|
|
1092
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
1093
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1094
|
+
* @returns {Match}
|
|
1095
|
+
*/
|
|
1096
|
+
findAll(text: string): Match[];
|
|
1097
|
+
/**
|
|
1098
|
+
* Returns true if and only if there is a match for the regex in the
|
|
1099
|
+
* string given.
|
|
1100
|
+
*
|
|
1101
|
+
* It is recommended to use this method if all you need to do is test
|
|
1102
|
+
* a match, since the underlying matching engine may be able to do less
|
|
1103
|
+
* work.
|
|
1104
|
+
*
|
|
1105
|
+
* # Example
|
|
1106
|
+
*
|
|
1107
|
+
* Test if some text contains at least one word with exactly 13
|
|
1108
|
+
* Unicode word characters:
|
|
1109
|
+
*
|
|
1110
|
+
* ```typescript
|
|
1111
|
+
* import { RRegex } from "rregex"
|
|
1112
|
+
*
|
|
1113
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
1114
|
+
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
1115
|
+
* ```
|
|
1116
|
+
*
|
|
1117
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
1118
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1119
|
+
* @return {boolean}
|
|
1120
|
+
*/
|
|
1121
|
+
isMatch(text: string): boolean;
|
|
1122
|
+
/**
|
|
1123
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
1124
|
+
* replacement provided. If `limit` is 0, then all non-overlapping matches
|
|
1125
|
+
* are replaced.
|
|
1126
|
+
*
|
|
1127
|
+
* See the documentation for `replace` for details on how to access
|
|
1128
|
+
* capturing group matches in the replacement string.
|
|
1129
|
+
*
|
|
1130
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
1131
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1132
|
+
* @param {number} limit - Max number of replacement
|
|
1133
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1134
|
+
* @returns {string}
|
|
1135
|
+
*/
|
|
1136
|
+
replacen(text: string, limit: number, rep: string): string;
|
|
1137
|
+
/**
|
|
1138
|
+
* Returns a string representing the regular expression
|
|
1139
|
+
*/
|
|
1146
1140
|
toString(): string;
|
|
1147
1141
|
}
|
|
1148
1142
|
/**
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1143
|
+
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
1144
|
+
* A regex set corresponds to the union of two or more regular expressions.
|
|
1145
|
+
*
|
|
1146
|
+
* That is, a regex set will match text where at least one of its constituent
|
|
1147
|
+
* regular expressions matches. A regex set as its formulated here provides a
|
|
1148
|
+
* touch more power: it will also report which regular expressions in the set match.
|
|
1149
|
+
* Indeed, this is the key difference between regex sets and a single `Regex`
|
|
1150
|
+
* with many alternates, since only one alternate can match at a time.
|
|
1151
|
+
*
|
|
1152
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
1153
|
+
*/
|
|
1160
1154
|
export class RRegexSet {
|
|
1161
1155
|
free(): void;
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
*/
|
|
1156
|
+
/**
|
|
1157
|
+
* Create a new regex set with the given regular expressions.
|
|
1158
|
+
*
|
|
1159
|
+
* This takes an of strings, if any item in the list is not a valid regular
|
|
1160
|
+
* expressions, then an error is returned.
|
|
1161
|
+
*
|
|
1162
|
+
* # Example
|
|
1163
|
+
*
|
|
1164
|
+
* Create a new regex set from an iterator of strings:
|
|
1165
|
+
*
|
|
1166
|
+
* ```typescript
|
|
1167
|
+
* import { RegexSet } from "rregex"
|
|
1168
|
+
*
|
|
1169
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
1170
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
1171
|
+
* ```
|
|
1172
|
+
*/
|
|
1180
1173
|
constructor(list: Array<any>);
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
*
|
|
1220
|
-
* The set can also be used to iterate over the matched indices.
|
|
1221
|
-
*
|
|
1222
|
-
* Note that as with searches using `Regex`, the expression is unanchored
|
|
1223
|
-
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
1224
|
-
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
1225
|
-
* text.
|
|
1226
|
-
*
|
|
1227
|
-
* # Example
|
|
1228
|
-
*
|
|
1229
|
-
* Tests which regular expressions match the given text:
|
|
1230
|
-
*
|
|
1231
|
-
* ```typescript
|
|
1232
|
-
* import { RegexSet } from "rregex"
|
|
1233
|
-
*
|
|
1234
|
-
* const set = new RegexSet([
|
|
1235
|
-
* "\\w+",
|
|
1236
|
-
* "\\d+",
|
|
1237
|
-
* "\\pL+",
|
|
1238
|
-
* "foo",
|
|
1239
|
-
* "bar",
|
|
1240
|
-
* "barfoo",
|
|
1241
|
-
* "foobar",
|
|
1242
|
-
* ])
|
|
1243
|
-
* const matches = set.matches("foobar")
|
|
1244
|
-
* expect(matches).toBe([0, 2, 3, 4, 6])
|
|
1245
|
-
* ```
|
|
1246
|
-
*
|
|
1247
|
-
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
|
|
1248
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1249
|
-
* @return {number[]}
|
|
1250
|
-
*/
|
|
1174
|
+
/**
|
|
1175
|
+
* Returns the set of regular expressions that match in the given text.
|
|
1176
|
+
*
|
|
1177
|
+
* The set returned contains the index of each regular expression that
|
|
1178
|
+
* matches in the given text. The index is in correspondence with the
|
|
1179
|
+
* order of regular expressions given to `RegexSet`'s constructor.
|
|
1180
|
+
*
|
|
1181
|
+
* The set can also be used to iterate over the matched indices.
|
|
1182
|
+
*
|
|
1183
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
1184
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
1185
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
1186
|
+
* text.
|
|
1187
|
+
*
|
|
1188
|
+
* # Example
|
|
1189
|
+
*
|
|
1190
|
+
* Tests which regular expressions match the given text:
|
|
1191
|
+
*
|
|
1192
|
+
* ```typescript
|
|
1193
|
+
* import { RegexSet } from "rregex"
|
|
1194
|
+
*
|
|
1195
|
+
* const set = new RegexSet([
|
|
1196
|
+
* "\\w+",
|
|
1197
|
+
* "\\d+",
|
|
1198
|
+
* "\\pL+",
|
|
1199
|
+
* "foo",
|
|
1200
|
+
* "bar",
|
|
1201
|
+
* "barfoo",
|
|
1202
|
+
* "foobar",
|
|
1203
|
+
* ])
|
|
1204
|
+
* const matches = set.matches("foobar")
|
|
1205
|
+
* expect(matches).toBe([0, 2, 3, 4, 6])
|
|
1206
|
+
* ```
|
|
1207
|
+
*
|
|
1208
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
|
|
1209
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1210
|
+
* @return {number[]}
|
|
1211
|
+
*/
|
|
1251
1212
|
matches(text: string): number[];
|
|
1213
|
+
/**
|
|
1214
|
+
* Returns true if and only if one of the regexes in this set matches
|
|
1215
|
+
* the text given.
|
|
1216
|
+
*
|
|
1217
|
+
* This method should be preferred if you only need to test whether any
|
|
1218
|
+
* of the regexes in the set should match, but don't care about *which*
|
|
1219
|
+
* regexes matched. This is because the underlying matching engine will
|
|
1220
|
+
* quit immediately after seeing the first match instead of continuing to
|
|
1221
|
+
* find all matches.
|
|
1222
|
+
*
|
|
1223
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
1224
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
1225
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
1226
|
+
* text.
|
|
1227
|
+
*
|
|
1228
|
+
* # Example
|
|
1229
|
+
*
|
|
1230
|
+
* Tests whether a set matches some text:
|
|
1231
|
+
*
|
|
1232
|
+
* ```typescript
|
|
1233
|
+
* import { RegexSet } from "rregex"
|
|
1234
|
+
*
|
|
1235
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
1236
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
1237
|
+
* expect(!set.is_match("☃")).toBe(false)
|
|
1238
|
+
* ```
|
|
1239
|
+
*
|
|
1240
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
1241
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1242
|
+
* @return {boolean}
|
|
1243
|
+
*/
|
|
1244
|
+
isMatch(text: string): boolean;
|
|
1252
1245
|
}
|
|
1253
1246
|
|
|
1254
1247
|
}
|
|
@@ -1257,47 +1250,51 @@ declare type InitInput = RequestInfo | URL | Response | BufferSource | WebAssemb
|
|
|
1257
1250
|
|
|
1258
1251
|
declare interface InitOutput {
|
|
1259
1252
|
readonly memory: WebAssembly.Memory;
|
|
1260
|
-
readonly __wbg_rregex_free: (a: number) => void;
|
|
1261
|
-
readonly
|
|
1253
|
+
readonly __wbg_rregex_free: (a: number, b: number) => void;
|
|
1254
|
+
readonly rregex_captureNames: (a: number) => [number, number];
|
|
1255
|
+
readonly rregex_captures: (a: number, b: number, c: number) => [number, number, number];
|
|
1256
|
+
readonly rregex_capturesAll: (a: number, b: number, c: number) => [number, number, number];
|
|
1257
|
+
readonly rregex_capturesLength: (a: number) => number;
|
|
1258
|
+
readonly rregex_find: (a: number, b: number, c: number) => [number, number, number];
|
|
1259
|
+
readonly rregex_findAll: (a: number, b: number, c: number) => [number, number, number];
|
|
1260
|
+
readonly rregex_findAt: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
1262
1261
|
readonly rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
1263
1262
|
readonly rregex_isMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1264
|
-
readonly
|
|
1265
|
-
readonly
|
|
1266
|
-
readonly
|
|
1267
|
-
readonly
|
|
1268
|
-
readonly
|
|
1269
|
-
readonly
|
|
1270
|
-
readonly
|
|
1271
|
-
readonly
|
|
1272
|
-
readonly
|
|
1273
|
-
readonly
|
|
1274
|
-
readonly
|
|
1275
|
-
readonly rregex_splitn: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
1276
|
-
readonly rregex_shortestMatch: (a: number, b: number, c: number, d: number) => void;
|
|
1277
|
-
readonly rregex_shortestMatchAt: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
1278
|
-
readonly rregex_syntax: (a: number, b: number) => void;
|
|
1279
|
-
readonly rregex_toString: (a: number, b: number) => void;
|
|
1280
|
-
readonly __wbg_rregexset_free: (a: number) => void;
|
|
1281
|
-
readonly rregexset_new: (a: number, b: number) => void;
|
|
1263
|
+
readonly rregex_new: (a: number, b: number) => [number, number, number];
|
|
1264
|
+
readonly rregex_replace: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
1265
|
+
readonly rregex_replaceAll: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
1266
|
+
readonly rregex_replacen: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
1267
|
+
readonly rregex_shortestMatch: (a: number, b: number, c: number) => number;
|
|
1268
|
+
readonly rregex_shortestMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1269
|
+
readonly rregex_split: (a: number, b: number, c: number) => [number, number];
|
|
1270
|
+
readonly rregex_splitn: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1271
|
+
readonly rregex_syntax: (a: number) => [number, number, number];
|
|
1272
|
+
readonly rregex_toString: (a: number) => [number, number];
|
|
1273
|
+
readonly __wbg_rregexset_free: (a: number, b: number) => void;
|
|
1282
1274
|
readonly rregexset_isMatch: (a: number, b: number, c: number) => number;
|
|
1283
|
-
readonly rregexset_matches: (a: number, b: number, c: number
|
|
1284
|
-
readonly
|
|
1275
|
+
readonly rregexset_matches: (a: number, b: number, c: number) => [number, number];
|
|
1276
|
+
readonly rregexset_new: (a: any) => [number, number, number];
|
|
1277
|
+
readonly escape: (a: number, b: number) => [number, number];
|
|
1278
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
1279
|
+
readonly __externref_table_alloc: () => number;
|
|
1280
|
+
readonly __wbindgen_export_2: WebAssembly.Table;
|
|
1285
1281
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
1286
1282
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
1287
|
-
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
1288
1283
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
1289
|
-
readonly
|
|
1284
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
1285
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
1286
|
+
readonly __wbindgen_start: () => void;
|
|
1290
1287
|
}
|
|
1291
1288
|
|
|
1292
1289
|
/**
|
|
1293
1290
|
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
1294
1291
|
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
1295
1292
|
*
|
|
1296
|
-
* @param {InitInput | Promise<InitInput>} module_or_path
|
|
1293
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
1297
1294
|
*
|
|
1298
1295
|
* @returns {Promise<InitOutput>}
|
|
1299
1296
|
*/
|
|
1300
|
-
declare function wasm_bindgen (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
1297
|
+
declare function wasm_bindgen (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
1301
1298
|
|
|
1302
1299
|
/** Build metadata */
|
|
1303
1300
|
export const metadata: {
|
|
@@ -1308,6 +1305,6 @@ export const metadata: {
|
|
|
1308
1305
|
],
|
|
1309
1306
|
"homepage": "http://rregex.dev",
|
|
1310
1307
|
"repository": "https://github.com/2fd/rregex",
|
|
1311
|
-
"regex": "1.10.
|
|
1308
|
+
"regex": "1.10.6",
|
|
1312
1309
|
"regex-syntax": "0.8.4"
|
|
1313
1310
|
}
|