rregex 1.11.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cf.d.ts +331 -331
- package/lib/cf.mjs +2 -2
- package/lib/commonjs.cjs +373 -373
- package/lib/commonjs.d.cts +319 -319
- package/lib/esm.d.ts +317 -317
- package/lib/esm.mjs +375 -375
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +12 -12
- package/lib/standalone.d.ts +331 -331
- package/lib/standalone.js +373 -373
- package/lib/types.d.ts +331 -331
- package/lib/web.d.ts +331 -331
- package/lib/web.js +375 -375
- package/package.json +2 -2
package/lib/standalone.d.ts
CHANGED
|
@@ -61,54 +61,6 @@ declare namespace wasm_bindgen {
|
|
|
61
61
|
value: string
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
/**
|
|
65
|
-
* Represents the capture groups for a single match.
|
|
66
|
-
*
|
|
67
|
-
* Capture groups refer to parts of a regex enclosed in parentheses. They can
|
|
68
|
-
* be optionally named. The purpose of capture groups is to be able to
|
|
69
|
-
* reference different parts of a match based on the original pattern. For
|
|
70
|
-
* example, say you want to match the individual letters in a 5-letter word:
|
|
71
|
-
*
|
|
72
|
-
* ```text
|
|
73
|
-
* (?<first>\w)(\w)(?:\w)\w(?<last>\w)
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* This regex has 4 capture groups:
|
|
77
|
-
*
|
|
78
|
-
* * The group at index `0` corresponds to the overall match. It is always
|
|
79
|
-
* present in every match and never has a name.
|
|
80
|
-
* * The group at index `1` with name `first` corresponding to the first
|
|
81
|
-
* letter.
|
|
82
|
-
* * The group at index `2` with no name corresponding to the second letter.
|
|
83
|
-
* * The group at index `3` with name `last` corresponding to the fifth and
|
|
84
|
-
* last letter.
|
|
85
|
-
*
|
|
86
|
-
* Notice that `(?:\w)` was not listed above as a capture group despite it
|
|
87
|
-
* being enclosed in parentheses. That's because `(?:pattern)` is a special
|
|
88
|
-
* syntax that permits grouping but *without* capturing. The reason for not
|
|
89
|
-
* treating it as a capture is that tracking and reporting capture groups
|
|
90
|
-
* requires additional state that may lead to slower searches. So using as few
|
|
91
|
-
* capture groups as possible can help performance. (Although the difference
|
|
92
|
-
* in performance of a couple of capture groups is likely immaterial.)
|
|
93
|
-
*
|
|
94
|
-
* # Example
|
|
95
|
-
*
|
|
96
|
-
* ```typescript
|
|
97
|
-
* import { RRegex } from "rregex"
|
|
98
|
-
*
|
|
99
|
-
* const re = new RRegex("(?<first>\\w)(\\w)(?:\\w)\\w(?<last>\\w)");
|
|
100
|
-
* const caps = re.captures("toady");
|
|
101
|
-
* expect(caps.get[0].value).toBe("toady");
|
|
102
|
-
* expect(caps.name["first"].value).toBe("t");
|
|
103
|
-
* expect(caps.get[2].value).toBe("o");
|
|
104
|
-
* expect(caps.name["last"].value).toBe("y");
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
export type Captures = {
|
|
108
|
-
get: Match[]
|
|
109
|
-
name: Record<string, Match>
|
|
110
|
-
}
|
|
111
|
-
|
|
112
64
|
/**
|
|
113
65
|
* A high-level intermediate representation (HIR) for a regular expression.
|
|
114
66
|
*/
|
|
@@ -634,6 +586,54 @@ declare namespace wasm_bindgen {
|
|
|
634
586
|
sub: Hir
|
|
635
587
|
}
|
|
636
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
|
+
|
|
637
637
|
/**
|
|
638
638
|
* The high-level intermediate representation for a capturing group.
|
|
639
639
|
*
|
|
@@ -701,38 +701,6 @@ declare namespace wasm_bindgen {
|
|
|
701
701
|
*/
|
|
702
702
|
export class RRegex {
|
|
703
703
|
free(): void;
|
|
704
|
-
/**
|
|
705
|
-
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
706
|
-
* to search, split or replace text in a string.
|
|
707
|
-
*
|
|
708
|
-
* If an invalid expression is given, then an error is returned.
|
|
709
|
-
*/
|
|
710
|
-
constructor(re: string);
|
|
711
|
-
/**
|
|
712
|
-
* Returns true if and only if there is a match for the regex in the
|
|
713
|
-
* string given.
|
|
714
|
-
*
|
|
715
|
-
* It is recommended to use this method if all you need to do is test
|
|
716
|
-
* a match, since the underlying matching engine may be able to do less
|
|
717
|
-
* work.
|
|
718
|
-
*
|
|
719
|
-
* # Example
|
|
720
|
-
*
|
|
721
|
-
* Test if some text contains at least one word with exactly 13
|
|
722
|
-
* Unicode word characters:
|
|
723
|
-
*
|
|
724
|
-
* ```typescript
|
|
725
|
-
* import { RRegex } from "rregex"
|
|
726
|
-
*
|
|
727
|
-
* const text = "I categorically deny having triskaidekaphobia."
|
|
728
|
-
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
729
|
-
* ```
|
|
730
|
-
*
|
|
731
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
732
|
-
* @param {string} text - The string against which to match the regular expression
|
|
733
|
-
* @return {boolean}
|
|
734
|
-
*/
|
|
735
|
-
isMatch(text: string): boolean;
|
|
736
704
|
/**
|
|
737
705
|
* Returns the same as is_match, but starts the search at the given offset.
|
|
738
706
|
* The significance of the starting point is that it takes the surrounding
|
|
@@ -746,121 +714,20 @@ declare namespace wasm_bindgen {
|
|
|
746
714
|
*/
|
|
747
715
|
isMatchAt(text: string, start: number): boolean;
|
|
748
716
|
/**
|
|
749
|
-
*
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
* Note that this should only be used if you want to discover the position
|
|
753
|
-
* of the match. Testing the existence of a match is faster if you use
|
|
754
|
-
* `isMatch`.
|
|
755
|
-
*
|
|
756
|
-
* # Example
|
|
757
|
-
*
|
|
758
|
-
* Find the start and end location of the first word with exactly 13
|
|
759
|
-
* Unicode word characters:
|
|
760
|
-
*
|
|
761
|
-
* ```typescript
|
|
762
|
-
* import { RRegex } from "rregex"
|
|
763
|
-
*
|
|
764
|
-
* const text = "I categorically deny having triskaidekaphobia."
|
|
765
|
-
* const m = new RRegex("\\b\\w{13}\\b").find(text)
|
|
766
|
-
* expect(m.start).toBe(2)
|
|
767
|
-
* expect(m.end).toBe(15)
|
|
768
|
-
* ```
|
|
769
|
-
*
|
|
770
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
771
|
-
* @param {string} text - The string against which to match the regular expression
|
|
772
|
-
* @return {Match}
|
|
773
|
-
*/
|
|
774
|
-
find(text: string): Match | undefined;
|
|
775
|
-
/**
|
|
776
|
-
* Returns the same as find, but starts the search at the given
|
|
777
|
-
* offset.
|
|
778
|
-
*
|
|
779
|
-
* The significance of the starting point is that it takes the surrounding
|
|
780
|
-
* context into consideration. For example, the `\A` anchor can only
|
|
781
|
-
* match when `start == 0`.
|
|
782
|
-
*
|
|
783
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
784
|
-
* @param {string} text - The string against which to match the regular expression
|
|
785
|
-
* @param {number} start - Zero-based index at which to start matching
|
|
786
|
-
* @returns {Match}
|
|
787
|
-
*/
|
|
788
|
-
findAt(text: string, start: number): Match | undefined;
|
|
789
|
-
/**
|
|
790
|
-
* Returns an array for each successive non-overlapping match in `text``,
|
|
791
|
-
* returning the start and end byte indices with respect to `text`.
|
|
792
|
-
*
|
|
793
|
-
* # Example
|
|
794
|
-
*
|
|
795
|
-
* Find the start and end location of every word with exactly 13 Unicode
|
|
796
|
-
* word characters:
|
|
797
|
-
*
|
|
798
|
-
* ```typescript
|
|
799
|
-
* import { RRegex } from "rregex"
|
|
800
|
-
*
|
|
801
|
-
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
802
|
-
* const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
|
|
803
|
-
* ```
|
|
804
|
-
*
|
|
805
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
806
|
-
* @param {string} text - The string against which to match the regular expression
|
|
807
|
-
* @returns {Match}
|
|
808
|
-
*/
|
|
809
|
-
findAll(text: string): Match[];
|
|
810
|
-
/**
|
|
811
|
-
* Returns a list of the capture names in this regex.
|
|
812
|
-
*
|
|
813
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
814
|
-
*/
|
|
815
|
-
captureNames(): (string | null)[];
|
|
816
|
-
/**
|
|
817
|
-
* Returns the capture groups corresponding to the leftmost-first
|
|
818
|
-
* match in `text`. Capture group `0` always corresponds to the entire
|
|
819
|
-
* match. If no match is found, then `undefined` is returned.
|
|
820
|
-
*
|
|
821
|
-
* You should only use `captures` if you need access to the location of
|
|
822
|
-
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
823
|
-
* the location of the overall match.
|
|
824
|
-
*
|
|
825
|
-
* # Examples
|
|
826
|
-
*
|
|
827
|
-
* Say you have some text with movie names and their release years,
|
|
828
|
-
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
829
|
-
* looking like that, while also extracting the movie name and its release
|
|
830
|
-
* year separately.
|
|
831
|
-
*
|
|
832
|
-
* ```typescript
|
|
833
|
-
* import { RRegex } from "rregex"
|
|
834
|
-
*
|
|
835
|
-
* const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
836
|
-
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
837
|
-
* const caps = re.captures(text)
|
|
838
|
-
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
839
|
-
* expect(caps.get[2].value).toBe("1941")
|
|
840
|
-
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
841
|
-
* ```
|
|
842
|
-
*
|
|
843
|
-
* Note that the full match is at capture group `0`. Each subsequent
|
|
844
|
-
* capture group is indexed by the order of its opening `(`.
|
|
845
|
-
*
|
|
846
|
-
* We can make this example a bit clearer by using *named* capture groups:
|
|
847
|
-
*
|
|
848
|
-
* ```typescript
|
|
849
|
-
* import { RRegex } from "rregex"
|
|
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`.
|
|
850
720
|
*
|
|
851
|
-
*
|
|
852
|
-
*
|
|
853
|
-
* const caps = re.captures(text)
|
|
854
|
-
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
855
|
-
* expect(caps.name["year"].value).toBe("1941")
|
|
856
|
-
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
857
|
-
* ```
|
|
721
|
+
* See the documentation for `replace` for details on how to access
|
|
722
|
+
* capturing group matches in the replacement string.
|
|
858
723
|
*
|
|
859
|
-
*
|
|
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
|
|
860
726
|
* @param {string} text - The string against which to match the regular expression
|
|
861
|
-
* @
|
|
727
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
728
|
+
* @returns {string}
|
|
862
729
|
*/
|
|
863
|
-
|
|
730
|
+
replaceAll(text: string, rep: string): string;
|
|
864
731
|
/**
|
|
865
732
|
* Returns a list with all the non-overlapping capture groups matched
|
|
866
733
|
* in `text`. This is operationally the same as `findAll`, except it
|
|
@@ -927,12 +794,168 @@ declare namespace wasm_bindgen {
|
|
|
927
794
|
*/
|
|
928
795
|
capturesLength(): number;
|
|
929
796
|
/**
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
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
|
+
*/
|
|
835
|
+
shortestMatch(text: string): number | undefined;
|
|
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
|
+
*/
|
|
848
|
+
shortestMatchAt(text: string, start: number): number | undefined;
|
|
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
|
+
*/
|
|
937
|
+
syntax(): Hir;
|
|
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.
|
|
936
959
|
*
|
|
937
960
|
* # Replacement string syntax
|
|
938
961
|
*
|
|
@@ -1003,137 +1026,114 @@ declare namespace wasm_bindgen {
|
|
|
1003
1026
|
*/
|
|
1004
1027
|
replace(text: string, rep: string): string;
|
|
1005
1028
|
/**
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
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.
|
|
1009
1032
|
*
|
|
1010
|
-
*
|
|
1011
|
-
* capturing group matches
|
|
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.
|
|
1012
1036
|
*
|
|
1013
|
-
*
|
|
1014
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1015
|
-
* @param {number} limit - Max number of replacement
|
|
1016
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1017
|
-
* @returns {string}
|
|
1018
|
-
*/
|
|
1019
|
-
replacen(text: string, limit: number, rep: string): string;
|
|
1020
|
-
/**
|
|
1021
|
-
* Replaces all non-overlapping matches in `text` with the replacement
|
|
1022
|
-
* provided. This is the same as calling `replacen` with `limit` set to
|
|
1023
|
-
* `0`.
|
|
1037
|
+
* # Examples
|
|
1024
1038
|
*
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
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.
|
|
1027
1043
|
*
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1030
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1031
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1032
|
-
* @returns {string}
|
|
1033
|
-
*/
|
|
1034
|
-
replaceAll(text: string, rep: string): string;
|
|
1035
|
-
/**
|
|
1036
|
-
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
1037
|
-
* regular expression. Namely, each element of the iterator corresponds to
|
|
1038
|
-
* text that *isn't* matched by the regular expression.
|
|
1044
|
+
* ```typescript
|
|
1045
|
+
* import { RRegex } from "rregex"
|
|
1039
1046
|
*
|
|
1040
|
-
*
|
|
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
|
+
* ```
|
|
1041
1054
|
*
|
|
1042
|
-
*
|
|
1055
|
+
* Note that the full match is at capture group `0`. Each subsequent
|
|
1056
|
+
* capture group is indexed by the order of its opening `(`.
|
|
1043
1057
|
*
|
|
1044
|
-
*
|
|
1058
|
+
* We can make this example a bit clearer by using *named* capture groups:
|
|
1045
1059
|
*
|
|
1046
1060
|
* ```typescript
|
|
1047
1061
|
* import { RRegex } from "rregex"
|
|
1048
1062
|
*
|
|
1049
|
-
* const re = new RRegex(
|
|
1050
|
-
* const
|
|
1051
|
-
*
|
|
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)")
|
|
1052
1069
|
* ```
|
|
1053
1070
|
*
|
|
1054
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.
|
|
1071
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
1055
1072
|
* @param {string} text - The string against which to match the regular expression
|
|
1056
|
-
* @returns {
|
|
1073
|
+
* @returns {Captures|undefined}
|
|
1057
1074
|
*/
|
|
1058
|
-
|
|
1075
|
+
captures(text: string): Captures | undefined;
|
|
1059
1076
|
/**
|
|
1060
|
-
* Returns an
|
|
1061
|
-
*
|
|
1062
|
-
* substrings.) Namely, each element of the iterator corresponds to text
|
|
1063
|
-
* that *isn't* matched by the regular expression. The remainder of the
|
|
1064
|
-
* string that is not split will be the last element in the iterator.
|
|
1065
|
-
*
|
|
1066
|
-
* This method will *not* copy the text given.
|
|
1077
|
+
* Returns an array for each successive non-overlapping match in `text``,
|
|
1078
|
+
* returning the start and end byte indices with respect to `text`.
|
|
1067
1079
|
*
|
|
1068
1080
|
* # Example
|
|
1069
1081
|
*
|
|
1070
|
-
*
|
|
1082
|
+
* Find the start and end location of every word with exactly 13 Unicode
|
|
1083
|
+
* word characters:
|
|
1071
1084
|
*
|
|
1072
1085
|
* ```typescript
|
|
1073
1086
|
* import { RRegex } from "rregex"
|
|
1074
1087
|
*
|
|
1075
|
-
* const
|
|
1076
|
-
* const
|
|
1077
|
-
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
1088
|
+
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
1089
|
+
* const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
|
|
1078
1090
|
* ```
|
|
1079
|
-
*
|
|
1091
|
+
*
|
|
1092
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
1080
1093
|
* @param {string} text - The string against which to match the regular expression
|
|
1081
|
-
* @
|
|
1082
|
-
* @returns {string[]}
|
|
1094
|
+
* @returns {Match}
|
|
1083
1095
|
*/
|
|
1084
|
-
|
|
1096
|
+
findAll(text: string): Match[];
|
|
1085
1097
|
/**
|
|
1086
|
-
* Returns
|
|
1087
|
-
*
|
|
1088
|
-
* This method may have the same performance characteristics as
|
|
1089
|
-
* `isMatch`, except it provides an end location for a match. In
|
|
1090
|
-
* particular, the location returned *may be shorter* than the proper end
|
|
1091
|
-
* of the leftmost-first match that you would find via `Regex.find`.
|
|
1098
|
+
* Returns true if and only if there is a match for the regex in the
|
|
1099
|
+
* string given.
|
|
1092
1100
|
*
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1096
|
-
* has determined that a match has occurred. This may vary depending on
|
|
1097
|
-
* which internal regex engine is used, and thus, the offset itself may
|
|
1098
|
-
* change.
|
|
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.
|
|
1099
1104
|
*
|
|
1100
1105
|
* # Example
|
|
1101
1106
|
*
|
|
1102
|
-
*
|
|
1103
|
-
*
|
|
1104
|
-
* `a`.
|
|
1107
|
+
* Test if some text contains at least one word with exactly 13
|
|
1108
|
+
* Unicode word characters:
|
|
1105
1109
|
*
|
|
1106
1110
|
* ```typescript
|
|
1107
1111
|
* import { RRegex } from "rregex"
|
|
1108
1112
|
*
|
|
1109
|
-
* const text = "
|
|
1110
|
-
*
|
|
1111
|
-
* expect(pos).toBe(1)
|
|
1113
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
1114
|
+
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
1112
1115
|
* ```
|
|
1113
1116
|
*
|
|
1114
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.
|
|
1117
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
1115
1118
|
* @param {string} text - The string against which to match the regular expression
|
|
1116
|
-
* @
|
|
1119
|
+
* @return {boolean}
|
|
1117
1120
|
*/
|
|
1118
|
-
|
|
1121
|
+
isMatch(text: string): boolean;
|
|
1119
1122
|
/**
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
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.
|
|
1122
1126
|
*
|
|
1123
|
-
*
|
|
1124
|
-
*
|
|
1125
|
-
*
|
|
1126
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.
|
|
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
|
|
1127
1131
|
* @param {string} text - The string against which to match the regular expression
|
|
1128
|
-
* @param {number}
|
|
1129
|
-
* @
|
|
1130
|
-
|
|
1131
|
-
shortestMatchAt(text: string, start: number): number | undefined;
|
|
1132
|
-
/**
|
|
1133
|
-
* Returns the regular expression into a high level intermediate
|
|
1134
|
-
* representation.
|
|
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
1135
|
*/
|
|
1136
|
-
|
|
1136
|
+
replacen(text: string, limit: number, rep: string): string;
|
|
1137
1137
|
/**
|
|
1138
1138
|
* Returns a string representing the regular expression
|
|
1139
1139
|
*/
|
|
@@ -1171,38 +1171,6 @@ declare namespace wasm_bindgen {
|
|
|
1171
1171
|
* ```
|
|
1172
1172
|
*/
|
|
1173
1173
|
constructor(list: Array<any>);
|
|
1174
|
-
/**
|
|
1175
|
-
* Returns true if and only if one of the regexes in this set matches
|
|
1176
|
-
* the text given.
|
|
1177
|
-
*
|
|
1178
|
-
* This method should be preferred if you only need to test whether any
|
|
1179
|
-
* of the regexes in the set should match, but don't care about *which*
|
|
1180
|
-
* regexes matched. This is because the underlying matching engine will
|
|
1181
|
-
* quit immediately after seeing the first match instead of continuing to
|
|
1182
|
-
* find all matches.
|
|
1183
|
-
*
|
|
1184
|
-
* Note that as with searches using `Regex`, the expression is unanchored
|
|
1185
|
-
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
1186
|
-
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
1187
|
-
* text.
|
|
1188
|
-
*
|
|
1189
|
-
* # Example
|
|
1190
|
-
*
|
|
1191
|
-
* Tests whether a set matches some text:
|
|
1192
|
-
*
|
|
1193
|
-
* ```typescript
|
|
1194
|
-
* import { RegexSet } from "rregex"
|
|
1195
|
-
*
|
|
1196
|
-
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
1197
|
-
* expect(set.is_match("foo")).toBe(true)
|
|
1198
|
-
* expect(!set.is_match("☃")).toBe(false)
|
|
1199
|
-
* ```
|
|
1200
|
-
*
|
|
1201
|
-
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
1202
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1203
|
-
* @return {boolean}
|
|
1204
|
-
*/
|
|
1205
|
-
isMatch(text: string): boolean;
|
|
1206
1174
|
/**
|
|
1207
1175
|
* Returns the set of regular expressions that match in the given text.
|
|
1208
1176
|
*
|
|
@@ -1242,6 +1210,38 @@ declare namespace wasm_bindgen {
|
|
|
1242
1210
|
* @return {number[]}
|
|
1243
1211
|
*/
|
|
1244
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;
|
|
1245
1245
|
}
|
|
1246
1246
|
|
|
1247
1247
|
}
|
|
@@ -1251,38 +1251,38 @@ declare type InitInput = RequestInfo | URL | Response | BufferSource | WebAssemb
|
|
|
1251
1251
|
declare interface InitOutput {
|
|
1252
1252
|
readonly memory: WebAssembly.Memory;
|
|
1253
1253
|
readonly __wbg_rregex_free: (a: number, b: number) => void;
|
|
1254
|
-
readonly rregex_new: (a: number, b: number) => [number, number, number];
|
|
1255
|
-
readonly rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
1256
|
-
readonly rregex_isMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1257
|
-
readonly rregex_find: (a: number, b: number, c: number) => [number, number, number];
|
|
1258
|
-
readonly rregex_findAt: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
1259
|
-
readonly rregex_findAll: (a: number, b: number, c: number) => [number, number, number];
|
|
1260
1254
|
readonly rregex_captureNames: (a: number) => [number, number];
|
|
1261
1255
|
readonly rregex_captures: (a: number, b: number, c: number) => [number, number, number];
|
|
1262
1256
|
readonly rregex_capturesAll: (a: number, b: number, c: number) => [number, number, number];
|
|
1263
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];
|
|
1261
|
+
readonly rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
1262
|
+
readonly rregex_isMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1263
|
+
readonly rregex_new: (a: number, b: number) => [number, number, number];
|
|
1264
1264
|
readonly rregex_replace: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
1265
|
-
readonly rregex_replacen: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
1266
1265
|
readonly rregex_replaceAll: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
1267
|
-
readonly
|
|
1268
|
-
readonly rregex_splitn: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1266
|
+
readonly rregex_replacen: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
1269
1267
|
readonly rregex_shortestMatch: (a: number, b: number, c: number) => number;
|
|
1270
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
1271
|
readonly rregex_syntax: (a: number) => [number, number, number];
|
|
1272
1272
|
readonly rregex_toString: (a: number) => [number, number];
|
|
1273
1273
|
readonly __wbg_rregexset_free: (a: number, b: number) => void;
|
|
1274
|
-
readonly
|
|
1274
|
+
readonly escape: (a: number, b: number) => [number, number];
|
|
1275
1275
|
readonly rregexset_isMatch: (a: number, b: number, c: number) => number;
|
|
1276
1276
|
readonly rregexset_matches: (a: number, b: number, c: number) => [number, number];
|
|
1277
|
-
readonly
|
|
1277
|
+
readonly rregexset_new: (a: any) => [number, number, number];
|
|
1278
1278
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
1279
1279
|
readonly __externref_table_alloc: () => number;
|
|
1280
1280
|
readonly __wbindgen_export_2: WebAssembly.Table;
|
|
1281
1281
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
1282
1282
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
1283
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
1283
1284
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
1284
1285
|
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
1285
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
1286
1286
|
readonly __wbindgen_start: () => void;
|
|
1287
1287
|
}
|
|
1288
1288
|
|
|
@@ -1305,6 +1305,6 @@ export const metadata: {
|
|
|
1305
1305
|
],
|
|
1306
1306
|
"homepage": "http://rregex.dev",
|
|
1307
1307
|
"repository": "https://github.com/2fd/rregex",
|
|
1308
|
-
"regex": "1.
|
|
1309
|
-
"regex-syntax": "0.8.
|
|
1308
|
+
"regex": "1.13.1",
|
|
1309
|
+
"regex-syntax": "0.8.11"
|
|
1310
1310
|
}
|