regexreplacefirst(
TEXT
,
PATTERN
,
TEMPLATE
)

The regexreplacefirst( function replaces the first occurrence of a regular expression pattern with new text.


Parameters

This function has three parameters:

text – is the item of text that you want to search through and possibly replace part of.

pattern – is the regular expression that specifies what text should be replaced (see Regular Expressions).

template – is the replacement text, which may include all or portions of the text being replaced.


Description

This function is similar to the replacefirst( function, but uses a regular expression to determine what text to replace (see Regular Expressions). Here is an example that replaces the first number in the text with the word [REDACTED].

regexreplacefirst("234 plus 189 is 423","[0-9]+","REDACTED") ☞ REDACTED plus 189 is 423

If the replacement template contains $0, it will be replaced by the found (also called captured) text. This formula uses this technique to surround the first number in the text with [ and ] brackets.

regexreplacefirst("234 plus 189 is 423","[0-9]+","[$0]") ☞ [234] plus 189 is 423

Note: Unlike the regexreplace( function, this function does not allow multiple pattern/template parameters. It also does not have an options parameter, and is always case insensitive. Use the regexreplacefirstexact( function if you need case sensitivity. This function also does not allow alternative capture groups ($1, $2, etc.) in the replacment template.


See Also


History

VersionStatusNotes
10.0NewNew in this version.