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/cf.d.ts
CHANGED
|
@@ -60,54 +60,6 @@ export type Match = {
|
|
|
60
60
|
value: string
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
* Represents the capture groups for a single match.
|
|
65
|
-
*
|
|
66
|
-
* Capture groups refer to parts of a regex enclosed in parentheses. They can
|
|
67
|
-
* be optionally named. The purpose of capture groups is to be able to
|
|
68
|
-
* reference different parts of a match based on the original pattern. For
|
|
69
|
-
* example, say you want to match the individual letters in a 5-letter word:
|
|
70
|
-
*
|
|
71
|
-
* ```text
|
|
72
|
-
* (?<first>\w)(\w)(?:\w)\w(?<last>\w)
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* This regex has 4 capture groups:
|
|
76
|
-
*
|
|
77
|
-
* * The group at index `0` corresponds to the overall match. It is always
|
|
78
|
-
* present in every match and never has a name.
|
|
79
|
-
* * The group at index `1` with name `first` corresponding to the first
|
|
80
|
-
* letter.
|
|
81
|
-
* * The group at index `2` with no name corresponding to the second letter.
|
|
82
|
-
* * The group at index `3` with name `last` corresponding to the fifth and
|
|
83
|
-
* last letter.
|
|
84
|
-
*
|
|
85
|
-
* Notice that `(?:\w)` was not listed above as a capture group despite it
|
|
86
|
-
* being enclosed in parentheses. That's because `(?:pattern)` is a special
|
|
87
|
-
* syntax that permits grouping but *without* capturing. The reason for not
|
|
88
|
-
* treating it as a capture is that tracking and reporting capture groups
|
|
89
|
-
* requires additional state that may lead to slower searches. So using as few
|
|
90
|
-
* capture groups as possible can help performance. (Although the difference
|
|
91
|
-
* in performance of a couple of capture groups is likely immaterial.)
|
|
92
|
-
*
|
|
93
|
-
* # Example
|
|
94
|
-
*
|
|
95
|
-
* ```typescript
|
|
96
|
-
* import { RRegex } from "rregex"
|
|
97
|
-
*
|
|
98
|
-
* const re = new RRegex("(?<first>\\w)(\\w)(?:\\w)\\w(?<last>\\w)");
|
|
99
|
-
* const caps = re.captures("toady");
|
|
100
|
-
* expect(caps.get[0].value).toBe("toady");
|
|
101
|
-
* expect(caps.name["first"].value).toBe("t");
|
|
102
|
-
* expect(caps.get[2].value).toBe("o");
|
|
103
|
-
* expect(caps.name["last"].value).toBe("y");
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
export type Captures = {
|
|
107
|
-
get: Match[]
|
|
108
|
-
name: Record<string, Match>
|
|
109
|
-
}
|
|
110
|
-
|
|
111
63
|
/**
|
|
112
64
|
* A high-level intermediate representation (HIR) for a regular expression.
|
|
113
65
|
*/
|
|
@@ -633,6 +585,54 @@ export type Repetition = {
|
|
|
633
585
|
sub: Hir
|
|
634
586
|
}
|
|
635
587
|
|
|
588
|
+
/**
|
|
589
|
+
* Represents the capture groups for a single match.
|
|
590
|
+
*
|
|
591
|
+
* Capture groups refer to parts of a regex enclosed in parentheses. They can
|
|
592
|
+
* be optionally named. The purpose of capture groups is to be able to
|
|
593
|
+
* reference different parts of a match based on the original pattern. For
|
|
594
|
+
* example, say you want to match the individual letters in a 5-letter word:
|
|
595
|
+
*
|
|
596
|
+
* ```text
|
|
597
|
+
* (?<first>\w)(\w)(?:\w)\w(?<last>\w)
|
|
598
|
+
* ```
|
|
599
|
+
*
|
|
600
|
+
* This regex has 4 capture groups:
|
|
601
|
+
*
|
|
602
|
+
* * The group at index `0` corresponds to the overall match. It is always
|
|
603
|
+
* present in every match and never has a name.
|
|
604
|
+
* * The group at index `1` with name `first` corresponding to the first
|
|
605
|
+
* letter.
|
|
606
|
+
* * The group at index `2` with no name corresponding to the second letter.
|
|
607
|
+
* * The group at index `3` with name `last` corresponding to the fifth and
|
|
608
|
+
* last letter.
|
|
609
|
+
*
|
|
610
|
+
* Notice that `(?:\w)` was not listed above as a capture group despite it
|
|
611
|
+
* being enclosed in parentheses. That's because `(?:pattern)` is a special
|
|
612
|
+
* syntax that permits grouping but *without* capturing. The reason for not
|
|
613
|
+
* treating it as a capture is that tracking and reporting capture groups
|
|
614
|
+
* requires additional state that may lead to slower searches. So using as few
|
|
615
|
+
* capture groups as possible can help performance. (Although the difference
|
|
616
|
+
* in performance of a couple of capture groups is likely immaterial.)
|
|
617
|
+
*
|
|
618
|
+
* # Example
|
|
619
|
+
*
|
|
620
|
+
* ```typescript
|
|
621
|
+
* import { RRegex } from "rregex"
|
|
622
|
+
*
|
|
623
|
+
* const re = new RRegex("(?<first>\\w)(\\w)(?:\\w)\\w(?<last>\\w)");
|
|
624
|
+
* const caps = re.captures("toady");
|
|
625
|
+
* expect(caps.get[0].value).toBe("toady");
|
|
626
|
+
* expect(caps.name["first"].value).toBe("t");
|
|
627
|
+
* expect(caps.get[2].value).toBe("o");
|
|
628
|
+
* expect(caps.name["last"].value).toBe("y");
|
|
629
|
+
* ```
|
|
630
|
+
*/
|
|
631
|
+
export type Captures = {
|
|
632
|
+
get: Match[]
|
|
633
|
+
name: Record<string, Match>
|
|
634
|
+
}
|
|
635
|
+
|
|
636
636
|
/**
|
|
637
637
|
* The high-level intermediate representation for a capturing group.
|
|
638
638
|
*
|
|
@@ -700,38 +700,6 @@ export type Capture = {
|
|
|
700
700
|
*/
|
|
701
701
|
export class RRegex {
|
|
702
702
|
free(): void;
|
|
703
|
-
/**
|
|
704
|
-
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
705
|
-
* to search, split or replace text in a string.
|
|
706
|
-
*
|
|
707
|
-
* If an invalid expression is given, then an error is returned.
|
|
708
|
-
*/
|
|
709
|
-
constructor(re: string);
|
|
710
|
-
/**
|
|
711
|
-
* Returns true if and only if there is a match for the regex in the
|
|
712
|
-
* string given.
|
|
713
|
-
*
|
|
714
|
-
* It is recommended to use this method if all you need to do is test
|
|
715
|
-
* a match, since the underlying matching engine may be able to do less
|
|
716
|
-
* work.
|
|
717
|
-
*
|
|
718
|
-
* # Example
|
|
719
|
-
*
|
|
720
|
-
* Test if some text contains at least one word with exactly 13
|
|
721
|
-
* Unicode word characters:
|
|
722
|
-
*
|
|
723
|
-
* ```typescript
|
|
724
|
-
* import { RRegex } from "rregex"
|
|
725
|
-
*
|
|
726
|
-
* const text = "I categorically deny having triskaidekaphobia."
|
|
727
|
-
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
728
|
-
* ```
|
|
729
|
-
*
|
|
730
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
731
|
-
* @param {string} text - The string against which to match the regular expression
|
|
732
|
-
* @return {boolean}
|
|
733
|
-
*/
|
|
734
|
-
isMatch(text: string): boolean;
|
|
735
703
|
/**
|
|
736
704
|
* Returns the same as is_match, but starts the search at the given offset.
|
|
737
705
|
* The significance of the starting point is that it takes the surrounding
|
|
@@ -745,121 +713,20 @@ export class RRegex {
|
|
|
745
713
|
*/
|
|
746
714
|
isMatchAt(text: string, start: number): boolean;
|
|
747
715
|
/**
|
|
748
|
-
*
|
|
749
|
-
*
|
|
750
|
-
*
|
|
751
|
-
* Note that this should only be used if you want to discover the position
|
|
752
|
-
* of the match. Testing the existence of a match is faster if you use
|
|
753
|
-
* `isMatch`.
|
|
754
|
-
*
|
|
755
|
-
* # Example
|
|
756
|
-
*
|
|
757
|
-
* Find the start and end location of the first word with exactly 13
|
|
758
|
-
* Unicode word characters:
|
|
759
|
-
*
|
|
760
|
-
* ```typescript
|
|
761
|
-
* import { RRegex } from "rregex"
|
|
762
|
-
*
|
|
763
|
-
* const text = "I categorically deny having triskaidekaphobia."
|
|
764
|
-
* const m = new RRegex("\\b\\w{13}\\b").find(text)
|
|
765
|
-
* expect(m.start).toBe(2)
|
|
766
|
-
* expect(m.end).toBe(15)
|
|
767
|
-
* ```
|
|
768
|
-
*
|
|
769
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
770
|
-
* @param {string} text - The string against which to match the regular expression
|
|
771
|
-
* @return {Match}
|
|
772
|
-
*/
|
|
773
|
-
find(text: string): Match | undefined;
|
|
774
|
-
/**
|
|
775
|
-
* Returns the same as find, but starts the search at the given
|
|
776
|
-
* offset.
|
|
777
|
-
*
|
|
778
|
-
* The significance of the starting point is that it takes the surrounding
|
|
779
|
-
* context into consideration. For example, the `\A` anchor can only
|
|
780
|
-
* match when `start == 0`.
|
|
781
|
-
*
|
|
782
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
783
|
-
* @param {string} text - The string against which to match the regular expression
|
|
784
|
-
* @param {number} start - Zero-based index at which to start matching
|
|
785
|
-
* @returns {Match}
|
|
786
|
-
*/
|
|
787
|
-
findAt(text: string, start: number): Match | undefined;
|
|
788
|
-
/**
|
|
789
|
-
* Returns an array for each successive non-overlapping match in `text``,
|
|
790
|
-
* returning the start and end byte indices with respect to `text`.
|
|
791
|
-
*
|
|
792
|
-
* # Example
|
|
793
|
-
*
|
|
794
|
-
* Find the start and end location of every word with exactly 13 Unicode
|
|
795
|
-
* word characters:
|
|
796
|
-
*
|
|
797
|
-
* ```typescript
|
|
798
|
-
* import { RRegex } from "rregex"
|
|
799
|
-
*
|
|
800
|
-
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
801
|
-
* const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
|
|
802
|
-
* ```
|
|
803
|
-
*
|
|
804
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
805
|
-
* @param {string} text - The string against which to match the regular expression
|
|
806
|
-
* @returns {Match}
|
|
807
|
-
*/
|
|
808
|
-
findAll(text: string): Match[];
|
|
809
|
-
/**
|
|
810
|
-
* Returns a list of the capture names in this regex.
|
|
811
|
-
*
|
|
812
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
813
|
-
*/
|
|
814
|
-
captureNames(): (string | null)[];
|
|
815
|
-
/**
|
|
816
|
-
* Returns the capture groups corresponding to the leftmost-first
|
|
817
|
-
* match in `text`. Capture group `0` always corresponds to the entire
|
|
818
|
-
* match. If no match is found, then `undefined` is returned.
|
|
819
|
-
*
|
|
820
|
-
* You should only use `captures` if you need access to the location of
|
|
821
|
-
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
822
|
-
* the location of the overall match.
|
|
823
|
-
*
|
|
824
|
-
* # Examples
|
|
825
|
-
*
|
|
826
|
-
* Say you have some text with movie names and their release years,
|
|
827
|
-
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
828
|
-
* looking like that, while also extracting the movie name and its release
|
|
829
|
-
* year separately.
|
|
830
|
-
*
|
|
831
|
-
* ```typescript
|
|
832
|
-
* import { RRegex } from "rregex"
|
|
833
|
-
*
|
|
834
|
-
* const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
835
|
-
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
836
|
-
* const caps = re.captures(text)
|
|
837
|
-
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
838
|
-
* expect(caps.get[2].value).toBe("1941")
|
|
839
|
-
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
840
|
-
* ```
|
|
841
|
-
*
|
|
842
|
-
* Note that the full match is at capture group `0`. Each subsequent
|
|
843
|
-
* capture group is indexed by the order of its opening `(`.
|
|
844
|
-
*
|
|
845
|
-
* We can make this example a bit clearer by using *named* capture groups:
|
|
846
|
-
*
|
|
847
|
-
* ```typescript
|
|
848
|
-
* import { RRegex } from "rregex"
|
|
716
|
+
* Replaces all non-overlapping matches in `text` with the replacement
|
|
717
|
+
* provided. This is the same as calling `replacen` with `limit` set to
|
|
718
|
+
* `0`.
|
|
849
719
|
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
852
|
-
* const caps = re.captures(text)
|
|
853
|
-
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
854
|
-
* expect(caps.name["year"].value).toBe("1941")
|
|
855
|
-
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
856
|
-
* ```
|
|
720
|
+
* See the documentation for `replace` for details on how to access
|
|
721
|
+
* capturing group matches in the replacement string.
|
|
857
722
|
*
|
|
858
|
-
*
|
|
723
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
724
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
859
725
|
* @param {string} text - The string against which to match the regular expression
|
|
860
|
-
* @
|
|
726
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
727
|
+
* @returns {string}
|
|
861
728
|
*/
|
|
862
|
-
|
|
729
|
+
replaceAll(text: string, rep: string): string;
|
|
863
730
|
/**
|
|
864
731
|
* Returns a list with all the non-overlapping capture groups matched
|
|
865
732
|
* in `text`. This is operationally the same as `findAll`, except it
|
|
@@ -926,12 +793,168 @@ export class RRegex {
|
|
|
926
793
|
*/
|
|
927
794
|
capturesLength(): number;
|
|
928
795
|
/**
|
|
929
|
-
*
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
796
|
+
* Returns a list of the capture names in this regex.
|
|
797
|
+
*
|
|
798
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
799
|
+
*/
|
|
800
|
+
captureNames(): (string | null)[];
|
|
801
|
+
/**
|
|
802
|
+
* Returns the end location of a match in the text given.
|
|
803
|
+
*
|
|
804
|
+
* This method may have the same performance characteristics as
|
|
805
|
+
* `isMatch`, except it provides an end location for a match. In
|
|
806
|
+
* particular, the location returned *may be shorter* than the proper end
|
|
807
|
+
* of the leftmost-first match that you would find via `Regex.find`.
|
|
808
|
+
*
|
|
809
|
+
* Note that it is not guaranteed that this routine finds the shortest or
|
|
810
|
+
* "earliest" possible match. Instead, the main idea of this API is that
|
|
811
|
+
* it returns the offset at the point at which the internal regex engine
|
|
812
|
+
* has determined that a match has occurred. This may vary depending on
|
|
813
|
+
* which internal regex engine is used, and thus, the offset itself may
|
|
814
|
+
* change.
|
|
815
|
+
*
|
|
816
|
+
* # Example
|
|
817
|
+
*
|
|
818
|
+
* Typically, `a+` would match the entire first sequence of `a` in some
|
|
819
|
+
* text, but `shortest_match` can give up as soon as it sees the first
|
|
820
|
+
* `a`.
|
|
821
|
+
*
|
|
822
|
+
* ```typescript
|
|
823
|
+
* import { RRegex } from "rregex"
|
|
824
|
+
*
|
|
825
|
+
* const text = "aaaaa"
|
|
826
|
+
* const = new RRegex("a+").shortest_match(text)
|
|
827
|
+
* expect(pos).toBe(1)
|
|
828
|
+
* ```
|
|
829
|
+
*
|
|
830
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
831
|
+
* @param {string} text - The string against which to match the regular expression
|
|
832
|
+
* @returns {number|undefined}
|
|
833
|
+
*/
|
|
834
|
+
shortestMatch(text: string): number | undefined;
|
|
835
|
+
/**
|
|
836
|
+
* Returns the same as `shortest_match`, but starts the search at the
|
|
837
|
+
* given offset.
|
|
838
|
+
*
|
|
839
|
+
* The significance of the starting point is that it takes the surrounding
|
|
840
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
841
|
+
* when `start == 0`.
|
|
842
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
843
|
+
* @param {string} text - The string against which to match the regular expression
|
|
844
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
845
|
+
* @returns {number|undefined}
|
|
846
|
+
*/
|
|
847
|
+
shortestMatchAt(text: string, start: number): number | undefined;
|
|
848
|
+
/**
|
|
849
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
850
|
+
* to search, split or replace text in a string.
|
|
851
|
+
*
|
|
852
|
+
* If an invalid expression is given, then an error is returned.
|
|
853
|
+
*/
|
|
854
|
+
constructor(re: string);
|
|
855
|
+
/**
|
|
856
|
+
* Returns the start and end byte range of the leftmost-first match in
|
|
857
|
+
* `text`. If no match exists, then `undefined` is returned.
|
|
858
|
+
*
|
|
859
|
+
* Note that this should only be used if you want to discover the position
|
|
860
|
+
* of the match. Testing the existence of a match is faster if you use
|
|
861
|
+
* `isMatch`.
|
|
862
|
+
*
|
|
863
|
+
* # Example
|
|
864
|
+
*
|
|
865
|
+
* Find the start and end location of the first word with exactly 13
|
|
866
|
+
* Unicode word characters:
|
|
867
|
+
*
|
|
868
|
+
* ```typescript
|
|
869
|
+
* import { RRegex } from "rregex"
|
|
870
|
+
*
|
|
871
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
872
|
+
* const m = new RRegex("\\b\\w{13}\\b").find(text)
|
|
873
|
+
* expect(m.start).toBe(2)
|
|
874
|
+
* expect(m.end).toBe(15)
|
|
875
|
+
* ```
|
|
876
|
+
*
|
|
877
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
878
|
+
* @param {string} text - The string against which to match the regular expression
|
|
879
|
+
* @return {Match}
|
|
880
|
+
*/
|
|
881
|
+
find(text: string): Match | undefined;
|
|
882
|
+
/**
|
|
883
|
+
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
884
|
+
* regular expression. Namely, each element of the iterator corresponds to
|
|
885
|
+
* text that *isn't* matched by the regular expression.
|
|
886
|
+
*
|
|
887
|
+
* This method will *not* copy the text given.
|
|
888
|
+
*
|
|
889
|
+
* # Example
|
|
890
|
+
*
|
|
891
|
+
* To split a string delimited by arbitrary amounts of spaces or tabs:
|
|
892
|
+
*
|
|
893
|
+
* ```typescript
|
|
894
|
+
* import { RRegex } from "rregex"
|
|
895
|
+
*
|
|
896
|
+
* const re = new RRegex(r"[ \\t]+")
|
|
897
|
+
* const fields = re.split("a b \t c\td e")
|
|
898
|
+
* expect(fields).toEqual(["a", "b", "c", "d", "e"])
|
|
899
|
+
* ```
|
|
900
|
+
*
|
|
901
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
902
|
+
* @param {string} text - The string against which to match the regular expression
|
|
903
|
+
* @returns {string[]}
|
|
904
|
+
*/
|
|
905
|
+
split(text: string): string[];
|
|
906
|
+
/**
|
|
907
|
+
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
908
|
+
* by a match of the regular expression. (A `limit` of `0` will return no
|
|
909
|
+
* substrings.) Namely, each element of the iterator corresponds to text
|
|
910
|
+
* that *isn't* matched by the regular expression. The remainder of the
|
|
911
|
+
* string that is not split will be the last element in the iterator.
|
|
912
|
+
*
|
|
913
|
+
* This method will *not* copy the text given.
|
|
914
|
+
*
|
|
915
|
+
* # Example
|
|
916
|
+
*
|
|
917
|
+
* Get the first two words in some text:
|
|
918
|
+
*
|
|
919
|
+
* ```typescript
|
|
920
|
+
* import { RRegex } from "rregex"
|
|
921
|
+
*
|
|
922
|
+
* const re = new RRegex(r"\\W+")
|
|
923
|
+
* const fields = re.splitn("Hey! How are you?", 3)
|
|
924
|
+
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
925
|
+
* ```
|
|
926
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
927
|
+
* @param {string} text - The string against which to match the regular expression
|
|
928
|
+
* @param {number} limit - Max number result elements
|
|
929
|
+
* @returns {string[]}
|
|
930
|
+
*/
|
|
931
|
+
splitn(text: string, limit: number): string[];
|
|
932
|
+
/**
|
|
933
|
+
* Returns the regular expression into a high level intermediate
|
|
934
|
+
* representation.
|
|
935
|
+
*/
|
|
936
|
+
syntax(): Hir;
|
|
937
|
+
/**
|
|
938
|
+
* Returns the same as find, but starts the search at the given
|
|
939
|
+
* offset.
|
|
940
|
+
*
|
|
941
|
+
* The significance of the starting point is that it takes the surrounding
|
|
942
|
+
* context into consideration. For example, the `\A` anchor can only
|
|
943
|
+
* match when `start == 0`.
|
|
944
|
+
*
|
|
945
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
946
|
+
* @param {string} text - The string against which to match the regular expression
|
|
947
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
948
|
+
* @returns {Match}
|
|
949
|
+
*/
|
|
950
|
+
findAt(text: string, start: number): Match | undefined;
|
|
951
|
+
/**
|
|
952
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
953
|
+
* The replacement can be a regular string (where `$N` and `$name` are
|
|
954
|
+
* expanded to match capture groups) or a function that takes the matches'
|
|
955
|
+
* `Captures` and returns the replaced string.
|
|
956
|
+
*
|
|
957
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
935
958
|
*
|
|
936
959
|
* # Replacement string syntax
|
|
937
960
|
*
|
|
@@ -1002,137 +1025,114 @@ export class RRegex {
|
|
|
1002
1025
|
*/
|
|
1003
1026
|
replace(text: string, rep: string): string;
|
|
1004
1027
|
/**
|
|
1005
|
-
*
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1028
|
+
* Returns the capture groups corresponding to the leftmost-first
|
|
1029
|
+
* match in `text`. Capture group `0` always corresponds to the entire
|
|
1030
|
+
* match. If no match is found, then `undefined` is returned.
|
|
1008
1031
|
*
|
|
1009
|
-
*
|
|
1010
|
-
* capturing group matches
|
|
1032
|
+
* You should only use `captures` if you need access to the location of
|
|
1033
|
+
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
1034
|
+
* the location of the overall match.
|
|
1011
1035
|
*
|
|
1012
|
-
*
|
|
1013
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1014
|
-
* @param {number} limit - Max number of replacement
|
|
1015
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1016
|
-
* @returns {string}
|
|
1017
|
-
*/
|
|
1018
|
-
replacen(text: string, limit: number, rep: string): string;
|
|
1019
|
-
/**
|
|
1020
|
-
* Replaces all non-overlapping matches in `text` with the replacement
|
|
1021
|
-
* provided. This is the same as calling `replacen` with `limit` set to
|
|
1022
|
-
* `0`.
|
|
1036
|
+
* # Examples
|
|
1023
1037
|
*
|
|
1024
|
-
*
|
|
1025
|
-
*
|
|
1038
|
+
* Say you have some text with movie names and their release years,
|
|
1039
|
+
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
1040
|
+
* looking like that, while also extracting the movie name and its release
|
|
1041
|
+
* year separately.
|
|
1026
1042
|
*
|
|
1027
|
-
*
|
|
1028
|
-
*
|
|
1029
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1030
|
-
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1031
|
-
* @returns {string}
|
|
1032
|
-
*/
|
|
1033
|
-
replaceAll(text: string, rep: string): string;
|
|
1034
|
-
/**
|
|
1035
|
-
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
1036
|
-
* regular expression. Namely, each element of the iterator corresponds to
|
|
1037
|
-
* text that *isn't* matched by the regular expression.
|
|
1043
|
+
* ```typescript
|
|
1044
|
+
* import { RRegex } from "rregex"
|
|
1038
1045
|
*
|
|
1039
|
-
*
|
|
1046
|
+
* const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
1047
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
1048
|
+
* const caps = re.captures(text)
|
|
1049
|
+
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
1050
|
+
* expect(caps.get[2].value).toBe("1941")
|
|
1051
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
1052
|
+
* ```
|
|
1040
1053
|
*
|
|
1041
|
-
*
|
|
1054
|
+
* Note that the full match is at capture group `0`. Each subsequent
|
|
1055
|
+
* capture group is indexed by the order of its opening `(`.
|
|
1042
1056
|
*
|
|
1043
|
-
*
|
|
1057
|
+
* We can make this example a bit clearer by using *named* capture groups:
|
|
1044
1058
|
*
|
|
1045
1059
|
* ```typescript
|
|
1046
1060
|
* import { RRegex } from "rregex"
|
|
1047
1061
|
*
|
|
1048
|
-
* const re = new RRegex(
|
|
1049
|
-
* const
|
|
1050
|
-
*
|
|
1062
|
+
* const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
1063
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
1064
|
+
* const caps = re.captures(text)
|
|
1065
|
+
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
1066
|
+
* expect(caps.name["year"].value).toBe("1941")
|
|
1067
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
1051
1068
|
* ```
|
|
1052
1069
|
*
|
|
1053
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.
|
|
1070
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
1054
1071
|
* @param {string} text - The string against which to match the regular expression
|
|
1055
|
-
* @returns {
|
|
1072
|
+
* @returns {Captures|undefined}
|
|
1056
1073
|
*/
|
|
1057
|
-
|
|
1074
|
+
captures(text: string): Captures | undefined;
|
|
1058
1075
|
/**
|
|
1059
|
-
* Returns an
|
|
1060
|
-
*
|
|
1061
|
-
* substrings.) Namely, each element of the iterator corresponds to text
|
|
1062
|
-
* that *isn't* matched by the regular expression. The remainder of the
|
|
1063
|
-
* string that is not split will be the last element in the iterator.
|
|
1064
|
-
*
|
|
1065
|
-
* This method will *not* copy the text given.
|
|
1076
|
+
* Returns an array for each successive non-overlapping match in `text``,
|
|
1077
|
+
* returning the start and end byte indices with respect to `text`.
|
|
1066
1078
|
*
|
|
1067
1079
|
* # Example
|
|
1068
1080
|
*
|
|
1069
|
-
*
|
|
1081
|
+
* Find the start and end location of every word with exactly 13 Unicode
|
|
1082
|
+
* word characters:
|
|
1070
1083
|
*
|
|
1071
1084
|
* ```typescript
|
|
1072
1085
|
* import { RRegex } from "rregex"
|
|
1073
1086
|
*
|
|
1074
|
-
* const
|
|
1075
|
-
* const
|
|
1076
|
-
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
1087
|
+
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
1088
|
+
* const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
|
|
1077
1089
|
* ```
|
|
1078
|
-
*
|
|
1090
|
+
*
|
|
1091
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
1079
1092
|
* @param {string} text - The string against which to match the regular expression
|
|
1080
|
-
* @
|
|
1081
|
-
* @returns {string[]}
|
|
1093
|
+
* @returns {Match}
|
|
1082
1094
|
*/
|
|
1083
|
-
|
|
1095
|
+
findAll(text: string): Match[];
|
|
1084
1096
|
/**
|
|
1085
|
-
* Returns
|
|
1086
|
-
*
|
|
1087
|
-
* This method may have the same performance characteristics as
|
|
1088
|
-
* `isMatch`, except it provides an end location for a match. In
|
|
1089
|
-
* particular, the location returned *may be shorter* than the proper end
|
|
1090
|
-
* of the leftmost-first match that you would find via `Regex.find`.
|
|
1097
|
+
* Returns true if and only if there is a match for the regex in the
|
|
1098
|
+
* string given.
|
|
1091
1099
|
*
|
|
1092
|
-
*
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
* has determined that a match has occurred. This may vary depending on
|
|
1096
|
-
* which internal regex engine is used, and thus, the offset itself may
|
|
1097
|
-
* change.
|
|
1100
|
+
* It is recommended to use this method if all you need to do is test
|
|
1101
|
+
* a match, since the underlying matching engine may be able to do less
|
|
1102
|
+
* work.
|
|
1098
1103
|
*
|
|
1099
1104
|
* # Example
|
|
1100
1105
|
*
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1103
|
-
* `a`.
|
|
1106
|
+
* Test if some text contains at least one word with exactly 13
|
|
1107
|
+
* Unicode word characters:
|
|
1104
1108
|
*
|
|
1105
1109
|
* ```typescript
|
|
1106
1110
|
* import { RRegex } from "rregex"
|
|
1107
1111
|
*
|
|
1108
|
-
* const text = "
|
|
1109
|
-
*
|
|
1110
|
-
* expect(pos).toBe(1)
|
|
1112
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
1113
|
+
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
1111
1114
|
* ```
|
|
1112
1115
|
*
|
|
1113
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.
|
|
1116
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
1114
1117
|
* @param {string} text - The string against which to match the regular expression
|
|
1115
|
-
* @
|
|
1118
|
+
* @return {boolean}
|
|
1116
1119
|
*/
|
|
1117
|
-
|
|
1120
|
+
isMatch(text: string): boolean;
|
|
1118
1121
|
/**
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1122
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
1123
|
+
* replacement provided. If `limit` is 0, then all non-overlapping matches
|
|
1124
|
+
* are replaced.
|
|
1121
1125
|
*
|
|
1122
|
-
*
|
|
1123
|
-
*
|
|
1124
|
-
*
|
|
1125
|
-
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.
|
|
1126
|
+
* See the documentation for `replace` for details on how to access
|
|
1127
|
+
* capturing group matches in the replacement string.
|
|
1128
|
+
*
|
|
1129
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
1126
1130
|
* @param {string} text - The string against which to match the regular expression
|
|
1127
|
-
* @param {number}
|
|
1128
|
-
* @
|
|
1129
|
-
|
|
1130
|
-
shortestMatchAt(text: string, start: number): number | undefined;
|
|
1131
|
-
/**
|
|
1132
|
-
* Returns the regular expression into a high level intermediate
|
|
1133
|
-
* representation.
|
|
1131
|
+
* @param {number} limit - Max number of replacement
|
|
1132
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
1133
|
+
* @returns {string}
|
|
1134
1134
|
*/
|
|
1135
|
-
|
|
1135
|
+
replacen(text: string, limit: number, rep: string): string;
|
|
1136
1136
|
/**
|
|
1137
1137
|
* Returns a string representing the regular expression
|
|
1138
1138
|
*/
|
|
@@ -1170,38 +1170,6 @@ export class RRegexSet {
|
|
|
1170
1170
|
* ```
|
|
1171
1171
|
*/
|
|
1172
1172
|
constructor(list: Array<any>);
|
|
1173
|
-
/**
|
|
1174
|
-
* Returns true if and only if one of the regexes in this set matches
|
|
1175
|
-
* the text given.
|
|
1176
|
-
*
|
|
1177
|
-
* This method should be preferred if you only need to test whether any
|
|
1178
|
-
* of the regexes in the set should match, but don't care about *which*
|
|
1179
|
-
* regexes matched. This is because the underlying matching engine will
|
|
1180
|
-
* quit immediately after seeing the first match instead of continuing to
|
|
1181
|
-
* find all matches.
|
|
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 whether a set matches some text:
|
|
1191
|
-
*
|
|
1192
|
-
* ```typescript
|
|
1193
|
-
* import { RegexSet } from "rregex"
|
|
1194
|
-
*
|
|
1195
|
-
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
1196
|
-
* expect(set.is_match("foo")).toBe(true)
|
|
1197
|
-
* expect(!set.is_match("☃")).toBe(false)
|
|
1198
|
-
* ```
|
|
1199
|
-
*
|
|
1200
|
-
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
1201
|
-
* @param {string} text - The string against which to match the regular expression
|
|
1202
|
-
* @return {boolean}
|
|
1203
|
-
*/
|
|
1204
|
-
isMatch(text: string): boolean;
|
|
1205
1173
|
/**
|
|
1206
1174
|
* Returns the set of regular expressions that match in the given text.
|
|
1207
1175
|
*
|
|
@@ -1241,6 +1209,38 @@ export class RRegexSet {
|
|
|
1241
1209
|
* @return {number[]}
|
|
1242
1210
|
*/
|
|
1243
1211
|
matches(text: string): number[];
|
|
1212
|
+
/**
|
|
1213
|
+
* Returns true if and only if one of the regexes in this set matches
|
|
1214
|
+
* the text given.
|
|
1215
|
+
*
|
|
1216
|
+
* This method should be preferred if you only need to test whether any
|
|
1217
|
+
* of the regexes in the set should match, but don't care about *which*
|
|
1218
|
+
* regexes matched. This is because the underlying matching engine will
|
|
1219
|
+
* quit immediately after seeing the first match instead of continuing to
|
|
1220
|
+
* find all matches.
|
|
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 whether a set matches some text:
|
|
1230
|
+
*
|
|
1231
|
+
* ```typescript
|
|
1232
|
+
* import { RegexSet } from "rregex"
|
|
1233
|
+
*
|
|
1234
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
1235
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
1236
|
+
* expect(!set.is_match("☃")).toBe(false)
|
|
1237
|
+
* ```
|
|
1238
|
+
*
|
|
1239
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
1240
|
+
* @param {string} text - The string against which to match the regular expression
|
|
1241
|
+
* @return {boolean}
|
|
1242
|
+
*/
|
|
1243
|
+
isMatch(text: string): boolean;
|
|
1244
1244
|
}
|
|
1245
1245
|
|
|
1246
1246
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
@@ -1248,38 +1248,38 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
1248
1248
|
export interface InitOutput {
|
|
1249
1249
|
readonly memory: WebAssembly.Memory;
|
|
1250
1250
|
readonly __wbg_rregex_free: (a: number, b: number) => void;
|
|
1251
|
-
readonly rregex_new: (a: number, b: number) => [number, number, number];
|
|
1252
|
-
readonly rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
1253
|
-
readonly rregex_isMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1254
|
-
readonly rregex_find: (a: number, b: number, c: number) => [number, number, number];
|
|
1255
|
-
readonly rregex_findAt: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
1256
|
-
readonly rregex_findAll: (a: number, b: number, c: number) => [number, number, number];
|
|
1257
1251
|
readonly rregex_captureNames: (a: number) => [number, number];
|
|
1258
1252
|
readonly rregex_captures: (a: number, b: number, c: number) => [number, number, number];
|
|
1259
1253
|
readonly rregex_capturesAll: (a: number, b: number, c: number) => [number, number, number];
|
|
1260
1254
|
readonly rregex_capturesLength: (a: number) => number;
|
|
1255
|
+
readonly rregex_find: (a: number, b: number, c: number) => [number, number, number];
|
|
1256
|
+
readonly rregex_findAll: (a: number, b: number, c: number) => [number, number, number];
|
|
1257
|
+
readonly rregex_findAt: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
1258
|
+
readonly rregex_isMatch: (a: number, b: number, c: number) => number;
|
|
1259
|
+
readonly rregex_isMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1260
|
+
readonly rregex_new: (a: number, b: number) => [number, number, number];
|
|
1261
1261
|
readonly rregex_replace: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
1262
|
-
readonly rregex_replacen: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
1263
1262
|
readonly rregex_replaceAll: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
1264
|
-
readonly
|
|
1265
|
-
readonly rregex_splitn: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1263
|
+
readonly rregex_replacen: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
1266
1264
|
readonly rregex_shortestMatch: (a: number, b: number, c: number) => number;
|
|
1267
1265
|
readonly rregex_shortestMatchAt: (a: number, b: number, c: number, d: number) => number;
|
|
1266
|
+
readonly rregex_split: (a: number, b: number, c: number) => [number, number];
|
|
1267
|
+
readonly rregex_splitn: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1268
1268
|
readonly rregex_syntax: (a: number) => [number, number, number];
|
|
1269
1269
|
readonly rregex_toString: (a: number) => [number, number];
|
|
1270
1270
|
readonly __wbg_rregexset_free: (a: number, b: number) => void;
|
|
1271
|
-
readonly
|
|
1271
|
+
readonly escape: (a: number, b: number) => [number, number];
|
|
1272
1272
|
readonly rregexset_isMatch: (a: number, b: number, c: number) => number;
|
|
1273
1273
|
readonly rregexset_matches: (a: number, b: number, c: number) => [number, number];
|
|
1274
|
-
readonly
|
|
1274
|
+
readonly rregexset_new: (a: any) => [number, number, number];
|
|
1275
1275
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
1276
1276
|
readonly __externref_table_alloc: () => number;
|
|
1277
1277
|
readonly __wbindgen_export_2: WebAssembly.Table;
|
|
1278
1278
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
1279
1279
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
1280
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
1280
1281
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
1281
1282
|
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
1282
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
1283
1283
|
readonly __wbindgen_start: () => void;
|
|
1284
1284
|
}
|
|
1285
1285
|
|
|
@@ -1313,6 +1313,6 @@ export const metadata: {
|
|
|
1313
1313
|
],
|
|
1314
1314
|
"homepage": "http://rregex.dev",
|
|
1315
1315
|
"repository": "https://github.com/2fd/rregex",
|
|
1316
|
-
"regex": "1.
|
|
1317
|
-
"regex-syntax": "0.8.
|
|
1316
|
+
"regex": "1.13.1",
|
|
1317
|
+
"regex-syntax": "0.8.11"
|
|
1318
1318
|
}
|