Choose where you’d like to start



The replaceFirst() function takes string, searchString, and replacementString as arguments.

It replaces the first occurrence of searchString with the replacementString in the string, and returns the string.

If searchString is not present in the string, it will return the string as it is.

Note: This function performs a case-sensitive search.

Return Type

  • Text


<variable> = <string>.replaceFirst( <searchString>, <replacementString>, <boolean>);


<variable> = replaceFirst( <string>, <searchString>, <replacementString>, <boolean>);
ParameterDescriptionData type
<variable>Variable which will contain the returned string.TEXT
<string>The string in which the first occurrence of searchString will be replaced with replacementString.TEXT

The first occurrence of this searchString will be replaced with replacementString, in the string.

Note: searchString can also be in the form of regular expression.
<replacementString>This replacementString will replace the first occurrence of searchString in the string.TEXT

Applicable values: true or false.

By default, the replaceFirst() function supports regular expression (i.e) it will not find and replace the special characters like $ in the source string.

This parameter can be used to specify if the regular expression is to be supported or escaped.

  • The value true denotes escaping the regular expression.
  • The value false denotes supporting the regular expression. By default, the value is taken as "false".


mainString="Create online database applications";
newText = replaceFirst(mainString, "online", "custom");   // returns Create custom database applications

useremail = "";
newdomain_email = replaceFirst(useremail,"\\@[a-z]{6}\\.[a-z]{3}","");

Get Started Now