Regex Find & Replace Tool
Test regular expressions with live match highlighting, then find and replace text using capture groups — privately, in your browser.
The global flag g was enabled so “Replace All” affects every match.
Capture groups (first matches)
| Match | Groups |
|---|
Regex cheat-sheet
| \d | Any digit (0–9) | \d{4} → 2026 |
| \w | Word char (letter, digit, _) | \w+ → hello_1 |
| \s | Whitespace (space, tab, newline) | a\sb → a b |
| . | Any character (except newline) | a.c → abc |
| * | 0 or more of the previous | ab* → a, ab, abb |
| + | 1 or more of the previous | ab+ → ab, abb |
| ? | 0 or 1 (optional) | colou?r → color, colour |
| {n,m} | Between n and m repetitions | \d{2,4} |
| ^ $ | Start / end of line (with m) | ^Line, end$ |
| [...] | Character set | [aeiou] → any vowel |
| (...) | Capture group → $1, $2 | (\w+)@ → user@ |
| (?<name>) | Named group → $<name> | (?<y>\d{4}) |
| (?=...) | Lookahead (must follow) | \d(?=px) |
| (?<=...) | Lookbehind (must precede) | (?<=\$)\d+ |
| \b | Word boundary | \bcat\b |
| | | Alternation (or) | cat|dog |
Everything runs in your browser — your text is never uploaded. Matching runs in a background worker with a 2-second safety timeout to prevent slow patterns from freezing the page.
What is the regex find & replace tool?
A regular expression — regex for short — is a compact way to describe a text pattern. Instead of searching for one fixed word, you describe the shape of what you want: any four digits, an email address, everything between two brackets, or every double space. That makes find-and-replace with regex far more powerful than a plain text search, because a single pattern can match thousands of different strings and you can rewrite them all at once using the pieces it captured. This tool lets you type a pattern and instantly see every match highlighted inside your text, build a replacement using those captured pieces, and generate the transformed result — all locally in your browser, with nothing uploaded. It uses the browser's native JavaScript regex engine, so what you test here behaves exactly like regex in your own JavaScript code.
How it works
You write a pattern in the Find field and, optionally, a replacement in the Replace field. As you type, the tool highlights matches live and shows a running count. Common tokens describe what to match: \d is any digit, \w is a word character (letter, digit or underscore), \s is whitespace, and a plain dot . matches any character. Quantifiers say how many: * means zero or more, + means one or more, ? means optional, and {2,4} means between two and four repetitions. Anchors ^ and $ mark the start and end of a line, [abc] is a character set, and parentheses (…) create a capture group you can reference in the replacement as $1, $2, and so on, or by name with $<name>. Flags change behaviour: g replaces every match rather than just the first, i ignores case, m makes ^ and $ match at each line, s lets the dot match newlines, and u enables full Unicode. If you only want to find or replace a literal string — say a real dot or parenthesis — switch on Plain text mode, which automatically escapes special characters so they are treated literally. When you are not sure a pattern is safe, remember that extremely complex expressions can be slow on large input; this tool runs matching in a background worker with a two-second timeout, so a runaway pattern is stopped instead of freezing the page. Test on a small sample first.
Worked example
Imagine you have messy contact data where phone numbers appear as “555.123.4567”, “(555) 123-4567” and “555 123 4567”, and you want them all in a clean (555) 123-4567 format. Use the pattern \(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4}) with the g flag. It captures the area code, prefix and line number into groups $1, $2 and $3 regardless of the separators used. Put ($1) $2-$3 in the Replace field and click Replace All: “555.123.4567” and “555 123 4567” both become “(555) 123-4567”. The same idea reformats dates — matching (\d{4})-(\d{2})-(\d{2}) and replacing with $3/$2/$1 turns 2026-09-29 into 29/09/2026. Because the source text is never mutated in place, you can keep tweaking the pattern until the result is exactly right, then copy it, download it, or swap it back into the source to chain another transformation.
Frequently asked questions
What is regex?
Regex (a regular expression) is a pattern that describes text — like “four digits” or “an email address” — so you can find or replace many different strings at once instead of one fixed word.
How do I replace all occurrences instead of just the first?
Enable the global flag g (or click Replace All, which turns it on automatically). Without g, only the first match is replaced.
What does $1 mean in the replace field?
Parentheses in your pattern create capture groups. $1 inserts what the first group matched, $2 the second, and so on. $& inserts the whole match, and $<name> inserts a named group.
Why isn't my pattern matching anything?
Common causes: special characters like . or ( need escaping (or use Plain text mode), case sensitivity (add the i flag), or the pattern being more specific than the text. Check the live highlight and match count as you type.
What is the difference between the g, i, and m flags?
g (global) affects every match, not just the first; i makes matching case-insensitive; m (multiline) makes the ^ and $ anchors match at the start and end of each line rather than the whole text.
Can I use this to clean up CSV or log files?
Yes. Paste the text and use patterns to normalise separators, strip columns, collapse repeated spaces, or reformat dates and numbers. Test on a small sample first, then apply to the full file.
Is my text uploaded anywhere?
No. All matching and replacing happen entirely in your browser; your text is never sent to a server. The pattern and flags are optionally saved in your browser's local storage for convenience.
How do I match a literal dot or parenthesis?
Escape it with a backslash — \. or \( — or simply turn on Plain text mode, which escapes all special characters so your input is matched literally.
Related tools
- JSON Formatter & ValidatorBeautify, minify and validate JSON with clear error messages — nothing is uploaded.
- Word & Character CounterCount words, characters, sentences and paragraphs in real time, with an estimated reading time.
- QR Code GeneratorCreate QR codes for links, Wi-Fi, contact cards, WhatsApp and more — with custom colours, a center logo, and PNG/SVG/JPG downloads.