Start typing to search 227 tools.
Regex Replace
Replace regex matches with text or capture-group references.
Ready to review
Review matches before copying the transformed text.
No regex matches found.
What Regex Replace does
Regex Replace is an online regex find-and-replace workspace for changing text rather than merely testing a match. It applies a PCRE pattern, shows exactly which source fragments were selected, and produces a separate transformed result.
Use literal replacement text to redact or normalize values. Use numbered references such as $1, $2, and $3 to preserve captured parts, reorder a date, swap name fields, wrap identifiers, or rebuild a line. A replacement limit can deliberately stop after a selected number of changes.
The analysis reports matches found, replacements made, source and result lengths, character change, capture values, and line and column positions. This page targets text transformation; use Regex Tester when the main goal is diagnosing groups and offsets, or Regex Extractor when the goal is collecting values without rewriting the source.
How to use
- Paste source text. Include values that must change and near-matches that must remain untouched.
- Define the find pattern. Choose a preset or enter a focused PCRE expression.
- Write the replacement. Enter literal text or combine it with numbered captures.
- Control scope. Select flags and use the limit when only the first few matches should change.
- Audit the result. Compare highlighted source matches, positions, replacement count, warnings, and final text.
Why use Regex Replace?
Focused controls, predictable output, and a workflow designed around this exact transformation.
Transformation-first workflow
The final replaced text is central, with the untouched source retained for comparison.
Capture-group restructuring
Keep and reorder matched components with numbered replacement references.
Visible change scope
Inspect each match, its captures, line, column, and the number of actual replacements.
Controlled replacement
Limit the number of changes and review warnings before copying the output.
Questions about Regex Replace
Practical details about input, output, privacy, limits, and the best way to use this tool.
01 What is the difference between Regex Replace and Regex Tester?
Regex Replace generates transformed text. Regex Tester focuses on diagnosing matches, named and numbered groups, offsets, line and column positions, and execution timing without rewriting the source.
02 How do capture groups work in a replacement?
Parentheses capture parts of the match. References such as $1 and $2 insert those captured values into the replacement in the order you choose.
03 Can I replace only the first match?
Yes. Set Maximum replacements to 1. Use -1 when every match should be replaced.
04 Why are there matches but fewer replacements?
A nonnegative replacement limit can stop processing before every detected match is changed. The summary and warning explain when this occurs.
05 Can Regex Replace modify Unicode text?
Yes. Keep the u flag for UTF-8 input such as Ukrainian, accented Latin text, or emoji.
06 Should I use regex to rewrite JSON or HTML?
Use a parser for complex structured formats. Regex replacement is best for narrow, clearly bounded text transformations.
07 Why did my replacement change too much text?
The pattern may be too broad or greedy. Add boundaries, narrow character classes, test negative cases, and review highlighted matches before copying the result.
08 Can I use confidential source data?
Avoid entering secrets or confidential production data into any environment you do not fully trust.
Read the complete Regex Guide
Understand regex syntax, character classes, groups, quantifiers, flags, practical examples, and common mistakes.
- Regex syntax and patterns
- Groups, flags, and quantifiers
- Debugging and best practices
Examples
Reformat an ISO date
Three numbered captures are reused in a different order.
Text: Released 2026-09-04
Pattern: (\d{4})-(\d{2})-(\d{2})
Replacement: $3/$2/$1
Released 04/09/2026
Swap comma-separated names
Line anchors keep the transformation scoped to one complete record.
Text: Lovelace, Ada Pattern: ^([^,]+),\s*(.+)$ Flags: mu Replacement: $2 $1
Ada Lovelace
Wrap order identifiers
The captured identifier is preserved and wrapped with literal brackets.
Text: Order API-2048 accepted
Pattern: \b([A-Z]{2,5}-\d{3,8})\b
Replacement: [$1]
Order [API-2048] accepted
A replacement workflow, not a match debugger
Regex Replace answers a specific question: what will the complete text become after the selected matches are rewritten? The workspace first detects source matches, records their positions and captures, and then applies the replacement. A pattern can match correctly while the replacement is still wrong, so both stages are shown.
The summary distinguishes matches found from replacements made. These numbers differ when a replacement limit stops early. Character delta shows whether the result became shorter or longer, while the changed state identifies a replacement that produced text identical to the source.
Regex find-and-replace examples
Convert an ISO date to day/month/year
Pattern: (\d{4})-(\d{2})-(\d{2})
Replacement: $3/$2/$1
Input: Released 2026-09-04
Output: Released 04/09/2026
Collapse repeated horizontal spaces
Pattern: [ \t]{2,}
Replacement: single space
Input: alpha beta
Output: alpha beta
Remove log-level prefixes per line
Pattern: ^(?:DEBUG|INFO|WARN|ERROR)\s*[:|-]\s*
Flags: mu
Replacement: empty
Swap comma-separated names
Pattern: ^([^,]+),\s*(.+)$
Flags: mu
Replacement: $2 $1
Input: Lovelace, Ada
Output: Ada Lovelace
Wrap order identifiers
Pattern: \b([A-Z]{2,5}-\d{3,8})\b
Replacement: [$1]
Input: Order API-2048 accepted
Output: Order [API-2048] accepted
Numbered capture references
A replacement reference uses the value captured by a pair of parentheses. If a date pattern contains year, month, and day groups, $3/$2/$1 reverses their order without retyping the values. Adding a new capturing group changes later numbers, so verify every reference after editing the pattern.
Use a non-capturing group such as (?:DEBUG|INFO) when parentheses are needed only to organize alternatives. This preserves the numbering of groups that the replacement actually uses.
Control the scope of every change
Anchors and boundaries prevent a transformation from spilling into nearby text. Multiline mode changes ^ and $ so they operate per line. Dot-all mode lets a dot cross line breaks. Case-insensitive mode can increase the set of affected values. Enable flags deliberately rather than copying them from an unrelated pattern.
Start with a short representative sample, use a limit of one when exploring an unfamiliar expression, and inspect every highlighted source match. Then test empty fields, unexpected punctuation, Unicode characters, and long nonmatching text.
Replacement safety and engine differences
Keep an untouched copy of important data. Regular expressions are not full parsers for HTML, JSON, XML, SQL, or programming languages. Use format-aware tools for structural edits and reserve regex for bounded text rules.
This workspace uses PCRE replacement syntax. Other languages can use different escaping or named-reference formats. Verify the final expression and replacement string in the destination runtime. See the PHP preg_replace reference and PCRE2 documentation.
Related Trexmi tools
Diagnose a pattern with Regex Tester PRO, generate a starting expression with Regex Builder, or collect matching values without modifying text with Regex Extractor.