Skip to main content

Replace text

Substitution replaces each selected match and keeps the unmatched text. Use it to rename a prefix or rearrange captured values.

Free
Included
Pro
Included
Self-hosted
Included
Compare plans

Replace an order prefix​

  1. Select JavaScript and Substitution mode.
  2. Enable g.
  3. Enter this pattern:
\bORD-([0-9]{4})\b
  1. Enter this input:
ORD-0042 pending
ORD-0187 sent
  1. Enter Order $1 in Substitution.

Open in regex101

The result is:

Order 0042 pending
Order 0187 sent

$1 inserts the first captured group. The spaces, status words, and line break remain because they are outside each match.

Nonmatching input and empty input​

InputOutput
ORD-0042 pendingOrder 0042 pending
ORD-42 invalidORD-42 invalid
XORD-0001 invalidXORD-0001 invalid
Empty inputEmpty output

Without g, only the first match changes in JavaScript. With no matches, substitution returns the original input.

Use the replacement syntax for your engine​

Replacement syntax is separate from pattern syntax. In this JavaScript example, $1 refers to group 1 and $$ inserts a literal dollar sign. Python uses different capture references in replacements. The editor explains replacement tokens for the active flavor.

If your output differs in another program, compare its replacement operation and string escaping.

The two replacements produce Order 0042 pending and Order 0187 sent.
Regular substitution changes ORD prefixes to Order and keeps the remaining text.