How to Use This Tool
Type a search and a replacement. Every match is highlighted before anything changes, and nothing is altered until you press the replace button.
The replacement string is not literal text
This is the first thing that surprises people. In a replacement, the dollar sign is special:
$1,$2— the first, second captured group$&— the entire match$`and$'— everything before and after the match$$— a literal dollar sign
So replacing something with $1.00 inserts capture group one followed by ".00", not a
price. Write $$1.00 when you mean a dollar. This tool flags a lone dollar sign in your
replacement, because it is the single most common cause of "the tool ate my text".
Greedy and lazy
Quantifiers like * and + take as much as they can and then give back only if
forced. So <.*> on <a>text<b> matches the whole line: it goes
to the end looking for >, finds the last one, and stops.
Adding a question mark makes the quantifier lazy: <.*?> takes as little as possible
and matches each tag separately. The difference is one character and it changes the result completely,
which is why so much regex debugging ends here.
The flags
- Ignore case — straightforward, and worth remembering that it applies to the search, not the replacement. Replacing "colour" with "color" case-insensitively will lowercase your capitals unless you capture and reuse them.
- ^ and $ per line — without this,
^means the start of the whole text. With it, the start of each line. This is the flag people want when adding a prefix to every line. - . matches new lines — by default the dot matches anything except a line break, which is a historical decision that catches people out when matching across lines.
Two habits worth having
Look at the preview first. The highlighted matches are the part that tells you whether your pattern means what you think. A pattern that matches too much is far more common than one that matches nothing, and only one of those is obvious.
Do not parse HTML with regex. It works on the example you tested and fails on nested tags, attributes containing angle brackets, and comments. For a one-off cleanup on text you control it is fine; for anything that has to keep working, use a parser.
