A focused regex find-and-replace tool: enter a pattern, a replacement string, pick your flags, and watch the substituted output update live. Capture-group references let you reorder and reshape matched text — ideal for reformatting dates, cleaning data, bulk-editing code, and one-off text transformations.
How it works
The tool builds a JavaScript RegExp from your pattern and the flags you select, then runs String.replace against your input. In the replacement string you can use the standard substitution tokens: $1, $2 for the first, second numbered capture group, $& for the whole match, $<name> for a named group, and $$ for a literal dollar sign. The flags control matching: g (global) replaces every match instead of just the first, i ignores case, m (multiline) makes ^ and $ match at line breaks, and s (dotall) lets . match newlines. A live match count confirms how many replacements were applied.
Replacement token reference
| Token | Meaning | Example |
|---|---|---|
$1, $2, … | Numbered capture groups | (\d+) → $1 |
$& | Entire match | prefix: $&_copy |
$<name> | Named capture group | (?<year>\d{4}) → $<year> |
$` | Text before the match | rarely needed |
$' | Text after the match | rarely needed |
$$ | Literal dollar sign | escape a $ |
Worked examples
1. Reformat ISO dates to day/month/year
- Find:
(\d{4})-(\d{2})-(\d{2})(global flag on) - Replace:
$3/$2/$1 - Input:
2026-05-28 and 2025-12-01 - Output:
28/05/2026 and 01/12/2025
2. Extract and reorder name parts
- Find:
(\w+),\s+(\w+)(global) - Replace:
$2 $1 - Input:
Smith, John→ Output:John Smith
3. Wrap all numbers in brackets
- Find:
\d+(global) - Replace:
[$&] - Input:
There are 3 cats and 12 dogs. - Output:
There are [3] cats and [12] dogs.
4. Strip HTML tags
- Find:
<[^>]+>(global) - Replace: “ (empty string)
- Input:
<b>Bold</b> and <i>italic</i> - Output:
Bold and italic
Common mistakes to avoid
- Forgetting the global flag — without
g, only the first match is replaced. Turn it on for any bulk substitution. - Not escaping dots —
.matches any character in a pattern. A literal period needs\.. - Using
$1when there is no group — if your pattern has no capturing parentheses,$1pastes literally. Add a group around what you want to reference. - Confusing
$&with$0— JavaScript uses$&for the whole match, not$0(which is not a valid token in the replacement string).
Patterns use the standard JavaScript engine, so what works here works in your code. Nothing is uploaded; all matching happens in your browser.