Skip to main content

replaceFirst (Function)

Finds the first substring of the input string that matches with the given regular expression, and replaces itwith the given replacement string.

Syntax

<STRING> str:replaceFirst(<STRING> input.string, <STRING> regex, <STRING> replacement.string)

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
input.stringThe input string that should be replaced.STRINGNoYes
regexThe regular expression with which the input string should be matched.STRINGNoYes
replacement.stringThe string with which the first substring of input string that matches the regular expression should be replaced.STRINGNoYes

Example 1

    replaceFirst("hello gdn A hello",  'gdn(.*)A', 'XXXX')

This returns a string after replacing the first substring with the given replacement string. In this scenario, the output is "hello XXXX hello".