Articles in this section

replacefirst helper

The replacefirst helper replaces only the first occurrence of a specified substring with another value, leaving all later occurrences unchanged. Use it to substitute a known prefix or leading marker without modifying the rest of the string.

Syntax

{{replacefirst str a b}}

str -- The input string. Required.

a -- The substring to replace. Required. Matching is case-sensitive.

b -- The replacement value. Required. Pass "" to delete the first occurrence.

Examples

Replace the first occurrence of a character

{{replacefirst record.text "a" "z"}}

Input:

{ "record": { "text": "a b a b a b" } }

Output: z b a b a b

The first "a" is replaced with "z". The remaining two instances are unchanged.

Replace the first occurrence of a word

{{replacefirst record.note "Order" "Invoice"}}

Input:

{ "record": { "note": "Order Order Order" } }

Output: Invoice Order Order

Only the first "Order" is replaced. The other two remain.

Usage notes

  • Only the first match is replaced. All subsequent occurrences remain unchanged.
  • Matching is case-sensitive: "Order" and "order" are treated as different substrings.
  • Pass "" as the replacement to delete only the first occurrence. To remove all occurrences, use {{regexReplace field "" "substring" "g"}} instead.
  • To replace all occurrences, use the replace helper instead.