Functions

matches
I

Checks whether the given string matches the provided regex.

replaceAll
I

Replaces each occurrence of the substrings, which match the provided regex from the given original string value with the provided replacement string.

replaceFirst
I

Replaces the first substring that matches the given regex with the provided replacement string.

split
I

Returns an array of strings by splitting a string using the provided delimiter.

matches

function matches(string stringToMatch, string regex) returns boolean
Isolated Function

Checks whether the given string matches the provided regex.

1boolean isMatched = regex:matches("Ballerina is great", "Ba[a-z ]+");

Parameters

  • stringToMatch string
  • The string to match the regex

  • regex string
  • The regex to match the string

Return Type

(boolean)

true if the provided string matches the regex or else false

replaceAll

function replaceAll(string originalString, string regex, string replacement) returns string
Isolated Function

Replaces each occurrence of the substrings, which match the provided regex from the given original string value with the provided replacement string.

1string result = regex:replaceAll("Ballerina is great", "\s+", "_");

Parameters

  • originalString string
  • The original string to replace the occurrences of the substrings that match the provided regex

  • regex string
  • The regex to match the substrings in the originalString to be replaced

  • replacement string
  • The replacement string to replace the subsgrings, which match the regex

Return Type

(string)

The resultant string with the replaced substrings

replaceFirst

function replaceFirst(string originalString, string regex, string replacement) returns string
Isolated Function

Replaces the first substring that matches the given regex with the provided replacement string.

1string result = regex:replaceFirst("Ballerina is great", "\s+", "_");

Parameters

  • originalString string
  • The original string to replace the occurrences of the substrings that match the provided regex

  • regex string
  • The regex to match the first substring in the originalString to be replaced

  • replacement string
  • The replacement string to replace the first substring, which matches the regex

Return Type

(string)

The resultant string with the replaced substring

split

function split(string receiver, string delimiter) returns string[ ]
Isolated Function

Returns an array of strings by splitting a string using the provided delimiter.

1string[] result = regex:split("Ballerina is great", " ");

Parameters

  • receiver string
  • The string to split

  • delimiter string
  • The delimiter to split by

Return Type

(string[ ])

An array of strings containing the individual strings that are split