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
Replace an order prefix
- Select JavaScript and Substitution mode.
- Enable
g. - Enter this pattern:
\bORD-([0-9]{4})\b
- Enter this input:
ORD-0042 pending
ORD-0187 sent
- Enter
Order $1in Substitution.
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
| Input | Output |
|---|---|
ORD-0042 pending | Order 0042 pending |
ORD-42 invalid | ORD-42 invalid |
XORD-0001 invalid | XORD-0001 invalid |
| Empty input | Empty 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.