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