@@ -52,7 +52,8 @@ API improvements are:
5252 public isolated function replaceAll(string originalString, string regex, Replacement replacement) returns string;
5353 ```
5454
55- - Change the type of replacement param from string to `Replacement` type and introduce a new param `startIndex`.
55+ - Introduce a new function to replace the first substring from the given start index of the string.
56+ This is an improved function from the `replaceFirst`.
5657 ```ballerina
5758 # Replaces the first substring that matches the given regex with
5859 # the provided replacement string or function.
@@ -71,3 +72,21 @@ API improvements are:
7172 public isolated function replace(string originalString, string regex, Replacement replacement, int startIndex = 0)
7273 returns string;
7374 ```
75+
76+ - Deprecate the existing `replaceFirst` function.
77+ ```ballerina
78+ # Replaces the first substring that matches the given regex with
79+ # the provided replacement string.
80+ # ```ballerina
81+ # string result = regex:replaceFirst("Ballerina is great", "\\s+", "_");
82+ # ```
83+ #
84+ # + originalString - The original string to replace the first occurrence of the
85+ # substring that matches the provided regex
86+ # + regex - The regex to match the first substring in the `originalString` to
87+ # be replaced
88+ # + replacement - The replacement string to replace the first substring, which
89+ # matches the regex
90+ # + return - The resultant string with the replaced substring
91+ public isolated function replaceFirst(string originalString, string regex, string replacement) returns string;
92+ ```
0 commit comments