Find and replace text with a regular expression

Replace regular-expression matches with text or a capture-aware function.

freeworks offlinenothing uploaded
ToolRegex Replace
Input
Output

How it works

Matches are found and replacement text or a callback builds the output; tokens such as $1 insert captured groups. Global mode replaces every non-overlapping match, while default mode replaces the first.

  • Standard replacement tokens keep capture substitutions concise.
  • Global mode is explicit because first-only replacement is the default.

Worked example

Reformat dates from YYYY-MM-DD to MM/DD/YYYY
Convert dates from YYYY-MM-DD to MM/DD/YYYY format using regex replace
Input
											Date: 2024-01-15 and 2024-12-31
										
Output
												: --  --
											

When to use this

Migrations, formatters, and log scrubbers replace matched text.

Edge cases

  • $& inserts the full match unless treated as literal replacement text.
  • Overlapping matches are skipped during global replacement.
  • Callback arguments differ from literal replacement tokens.

References