@@ -595,6 +595,7 @@ let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match)
595
595
String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls"
596
596
```
597
597
*/
598
+ @deprecated("Use `replaceRegExpBy0Unsafe` instead")
598
599
@send
599
600
external unsafeReplaceRegExpBy0: (
600
601
string,
@@ -618,6 +619,7 @@ let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => {
618
619
String.unsafeReplaceRegExpBy1(str, re, matchFn) == "Jony is 41"
619
620
```
620
621
*/
622
+ @deprecated("Use `replaceRegExpBy1Unsafe` instead")
621
623
@send
622
624
external unsafeReplaceRegExpBy1: (
623
625
string,
@@ -644,6 +646,7 @@ let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => {
644
646
String.unsafeReplaceRegExpBy2(str, re, matchFn) == "42"
645
647
```
646
648
*/
649
+ @deprecated("Use `replaceRegExpBy2Unsafe` instead")
647
650
@send
648
651
external unsafeReplaceRegExpBy2: (
649
652
string,
@@ -652,10 +655,11 @@ external unsafeReplaceRegExpBy2: (
652
655
) => string = "replace"
653
656
654
657
/**
655
- `unsafeReplaceRegExpBy3(str, regexp, f)`. Like `unsafeReplaceRegExpBy1 `, but `f`
658
+ `unsafeReplaceRegExpBy3(str, regexp, f)`. Like `unsafeReplaceRegExpBy2 `, but `f`
656
659
has three group parameters.
657
660
See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) on MDN.
658
661
*/
662
+ @deprecated("Use `replaceRegExpBy3Unsafe` instead")
659
663
@send
660
664
external unsafeReplaceRegExpBy3: (
661
665
string,
@@ -670,6 +674,98 @@ external unsafeReplaceRegExpBy3: (
670
674
) => string,
671
675
) => string = "replace"
672
676
677
+ /**
678
+ `replaceRegExpBy0Unsafe(str, regex, f)` returns a new `string` with some or all
679
+ matches of a pattern with no capturing parentheses replaced by the value
680
+ returned from the given function. The function receives as its parameters the
681
+ matched string, the offset at which the match begins, and the whole string being
682
+ matched.
683
+ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) on MDN.
684
+
685
+ ## Examples
686
+
687
+ ```rescript
688
+ let str = "beautiful vowels"
689
+ let re = %re("/[aeiou]/g")
690
+ let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match)
691
+ String.replaceRegExpBy0Unsafe(str, re, matchFn) == "bEAUtIfUl vOwEls"
692
+ ```
693
+ */
694
+ @send
695
+ external replaceRegExpBy0Unsafe: (
696
+ string,
697
+ Stdlib_RegExp.t,
698
+ (~match: string, ~offset: int, ~input: string) => string,
699
+ ) => string = "replace"
700
+
701
+ /**
702
+ `replaceRegExpBy1Unsafe(str, regexp, f)`. Like `replaceRegExpBy0Unsafe`, but `f`
703
+ has `group1` parameter.
704
+ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) on MDN.
705
+
706
+ ## Examples
707
+
708
+ ```rescript
709
+ let str = "Jony is 40"
710
+ let re = %re("/(Jony is )\d+/g")
711
+ let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => {
712
+ group1 ++ "41"
713
+ }
714
+ String.replaceRegExpBy1Unsafe(str, re, matchFn) == "Jony is 41"
715
+ ```
716
+ */
717
+ @send
718
+ external replaceRegExpBy1Unsafe: (
719
+ string,
720
+ Stdlib_RegExp.t,
721
+ (~match: string, ~group1: string, ~offset: int, ~input: string) => string,
722
+ ) => string = "replace"
723
+
724
+ /**
725
+ `replaceRegExpBy2Unsafe(str, regexp, f)`. Like `replaceRegExpBy1Unsafe`, but `f`
726
+ has two group parameters.
727
+ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) on MDN.
728
+
729
+ ## Examples
730
+
731
+ ```rescript
732
+ let str = "7 times 6"
733
+ let re = %re("/(\d+) times (\d+)/")
734
+ let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => {
735
+ switch (Int.fromString(group1), Int.fromString(group2)) {
736
+ | (Some(x), Some(y)) => Int.toString(x * y)
737
+ | _ => "???"
738
+ }
739
+ }
740
+ String.replaceRegExpBy2Unsafe(str, re, matchFn) == "42"
741
+ ```
742
+ */
743
+ @send
744
+ external replaceRegExpBy2Unsafe: (
745
+ string,
746
+ Stdlib_RegExp.t,
747
+ (~match: string, ~group1: string, ~group2: string, ~offset: int, ~input: string) => string,
748
+ ) => string = "replace"
749
+
750
+ /**
751
+ `replaceRegExpBy3Unsafe(str, regexp, f)`. Like `replaceRegExpBy2Unsafe`, but `f`
752
+ has three group parameters.
753
+ See [`String.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) on MDN.
754
+ */
755
+ @send
756
+ external replaceRegExpBy3Unsafe: (
757
+ string,
758
+ Stdlib_RegExp.t,
759
+ (
760
+ ~match: string,
761
+ ~group1: string,
762
+ ~group2: string,
763
+ ~group3: string,
764
+ ~offset: int,
765
+ ~input: string,
766
+ ) => string,
767
+ ) => string = "replace"
768
+
673
769
/**
674
770
`search(str, regexp)` returns the starting position of the first match of
675
771
`regexp` in the given `str`, or -1 if there is no match.
0 commit comments