@@ -18,6 +18,8 @@ import ballerina/jballerina.java;
1818import ballerina /lang .'string as strings ;
1919
2020# Checks whether the given string matches the provided regex.
21+ # Note that `\\` is used as for escape sequence and `\\\\` is used to inserts a backslash
22+ # character in the string or regular expression.
2123# ```ballerina
2224# boolean isMatched = regex:matches("Ballerina is great", "Ba[a-z ]+");
2325# ```
@@ -31,6 +33,8 @@ public isolated function matches(string stringToMatch, string regex) returns boo
3133
3234# Replaces the first substring that matches the given regex with
3335# the provided replacement string or string returned by the provided function.
36+ # Note that `\\` is used as for escape sequence and `\\\\` is used to inserts a backslash
37+ # character in the string or regular expression.
3438# ```ballerina
3539# string result = regex:replace("Ballerina is great", "\\s+", "_");
3640# ```
@@ -60,8 +64,9 @@ public isolated function replace(string originalString, string regex, Replacemen
6064}
6165
6266# Replaces each occurrence of the substrings, which match the provided
63- # regex from the given original string value with the
64- # provided replacement string.
67+ # regex from the given original string value with the provided replacement string.
68+ # Note that `\\` is used as for escape sequence and `\\\\` is used to inserts a backslash
69+ # character in the string or regular expression.
6570# ```ballerina
6671# string result = regex:replaceAll("Ballerina is great", "\\s+", "_");
6772# ```
@@ -92,6 +97,8 @@ public isolated function replaceAll(string originalString, string regex, Replace
9297
9398# Replaces the first substring that matches the given regex with
9499# the provided replacement string.
100+ # Note that `\\` is used as for escape sequence and `\\\\` is used to inserts a backslash
101+ # character in the string or regular expression.
95102# ```ballerina
96103# string result = regex:replaceFirst("Ballerina is great", "\\s+", "_");
97104# ```
@@ -107,20 +114,13 @@ public isolated function replaceAll(string originalString, string regex, Replace
107114# This function will be removed in a later. Use `replace` instead.
108115@deprecated
109116public isolated function replaceFirst(string originalString , string regex , string replacement ) returns string {
110- handle | error value = trap replaceFirstExternal (java : fromString (originalString ), java : fromString (regex ),
111- java : fromString (replacement ));
112- if value is handle {
113- string ? updatedString = java : toString (value );
114- if updatedString is string {
115- return updatedString ;
116- }
117- panic error (string ` error occurred while replacing ${regex } in ${originalString }` );
118- }
119- panic error (string ` error occurred while replacing ${regex } in ${originalString }: ` + value .detail ().toString ());
117+ return replace (originalString , regex , replacement );
120118}
121119
122120# Returns an array of strings by splitting a string using the provided
123121# regex as the delimiter.
122+ # Note that `\\` is used as for escape sequence and `\\\\` is used to inserts a backslash
123+ # character in the string or regular expression.
124124# ```ballerina
125125# string[] result = regex:split("Ballerina is great", " ");
126126# ```
@@ -134,6 +134,8 @@ public isolated function split(string receiver, string delimiter) returns string
134134}
135135
136136# Returns the first substring in str that matches the regex.
137+ # Note that `\\` is used as for escape sequence and `\\\\` is used to inserts a backslash
138+ # character in the string or regular expression.
137139# ```ballerina
138140# regex:Match? result = regex:search("Betty Botter bought some butter but she said the butter’s bitter.",
139141# "\\b[bB].tt[a-z]*");
@@ -161,6 +163,8 @@ public isolated function search(string str, string regex, int startIndex = 0) re
161163}
162164
163165# Returns all substrings in string that match the regex.
166+ # Note that `\\` is used as for escape sequence and `\\\\` is used to inserts a backslash
167+ # character in the string or regular expression.
164168# ```ballerina
165169# regex:Match[] result = regex:searchAll("Betty Botter bought some butter but she said the butter’s bitter.",
166170# "\\b[bB].tt[a-z]*");
0 commit comments