What is Regex Replace?
Regex Replace applies a regular expression to your text and rewrites every match using a replacement pattern. Instead of searching for a fixed word, you match a shape - a date, a phone number, a tag - and rebuild it however you want. Capture group backreferences like $1 and $2 let you reorder and reformat the parts you matched, so turning 2024-01-15 into 15/01/2024 is a single expression rather than a hand edit on every line.
To replace with regex on real text, click Load Sample. The Find field holds (\d{4})-(\d{2})-(\d{2}), the Replace field holds $3/$2/$1, and the first line, Invoice 2024-01-15 was paid on 2024-02-03., becomes Invoice 15/01/2024 was paid on 03/02/2024., with 3 replacements counted across the sample. Named groups work the same way: (?<y>\d{4})-(?<m>\d{2}) with $<m>.$<y> turns 2024-01 into 01.2024. Type \3/\2/\1 instead, as you would in sed or Python, and the output is the literal text \3/\2/\1.
The tool uses your browser's own JavaScript RegExp engine, which follows the same ECMAScript rules as Node.js, and the replacement field follows the standard String.replace syntax: $1 through $9 for numbered groups, $<name> for named groups, $& for the whole match, and $$ for a literal dollar sign. You see the rewritten output and the number of replacements immediately, so you can confirm a pattern does what you expect before you run it against a large file or paste it into code.
Everything runs client-side. Your patterns and text - which often include log lines, source code, or records with personal data - are never uploaded or stored, and the tool keeps working with your connection off. That makes it safe for reformatting sensitive data that should never leave your device.
The replacement string has its own small syntax, and it is the source of most surprises. A dollar sign is special: $1 inserts the first capture group, $& the whole match, and $` and $' the text before and after it. That means a literal dollar in your replacement has to be written $$, which is why replacing a price with a hardcoded $5 can produce something unexpected. Named groups are referenced as $<name>. Escapes such as backslash n are part of the pattern language rather than the replacement, and because the Replace field here is a single line, this tool cannot insert a newline into the output. Replacements are computed left to right against the original string, so a replacement that produces text matching the pattern is not re-scanned.
How to use Regex Replace?
Enter your pattern
Type a regular expression into the Find field, written without the surrounding slashes. Click Load Sample to start from a working date-reformatting example.
Write the replacement
Put the replacement in the Replace field. Use $1, $2 and named groups like $<year> to reuse the parts your pattern captured, or leave it empty to delete every match.
Choose flags and add text
Toggle flags such as g (replace all), i (ignore case) and m (multiline), then paste the text you want to transform. The output and replacement count update live.
Copy the result
Review the rewritten text, confirm the replacement count matches what you expect, and copy the output when it is correct.
Key Features
Capture Group Backreferences
Reorder and reformat matched text with $1, $2 and named $<name> references, so you can restructure data rather than only delete it
Live Replacement Count
See exactly how many matches were replaced as you type, so you can catch a pattern that matches too much or too little before you commit
Six Flag Toggles
Toggle global, ignore-case, multiline, dotAll, unicode, and sticky - the g, i, m, s, u and y flags - and see the effect on the output immediately
Accurate Error Messages
Invalid patterns are caught and reported with the JavaScript engine's own error message, such as Unterminated group, pointing you at the syntax problem
Frequently Asked Questions
Related Tools
Email Extractor
Extract email addresses, URLs, phone numbers, and IPv4 addresses from any block of text. De-duplicate, sort, and copy the results. Runs client-side.
Regex Explainer
Paste a regular expression and get a clear, token-by-token explanation in plain English, including flags, groups, and quantifiers.
Regex Tester
Test regular expressions against sample text with live match highlighting, capture groups, and full flag support
JSON Minifier
Minify JSON by removing whitespace, or beautify it with clean indentation, with live size-savings stats and exact parser error messages
Comments
0 comments
No comments yet. Be the first to share your thoughts!