Find & Replace
runs in your browserSearch and replace text or regular expressions, with live match highlighting, capture groups and a list of every match.
Text
Result
about this tool
Plain text or a pattern
By default the search box is literal: what you type is what is matched, and
regular expression characters like . and ( have no special meaning. Turn on
regex and the box becomes a JavaScript regular expression, with matches
highlighted in the text as you type so you can see what a pattern catches before
you replace anything.
To work a pattern out before replacing with it, the regex tester uses the same engine and shows every match and group as you type.
Capture groups in the replacement
With regex on, $1, $2 and so on in the replacement field insert what the
corresponding bracketed group matched. This is what turns find-and-replace into
a reformatting tool. Given:
Ada Lovelace, born 1815
the pattern (\w+) (\w+), born (\d{4}) with replacement $3: $2, $1 produces:
1815: Lovelace, Ada
That one mechanism reorders a name column, rewrites a date format, or converts a
list of URLs into Markdown links. $& inserts the whole match, and $$
inserts a literal dollar sign.
The flags, and what they actually do
Global replaces every occurrence rather than only the first. On by default, because replacing one is rarely what anyone wants.
Ignore case matches regardless of capitalisation. Note that the replacement does not adapt — replacing "cat" with "dog" turns "Cat" into "dog", not "Dog".
Multiline changes what ^ and $ mean: with it on they match the start and
end of each line, with it off only the start and end of the whole text. If you
are anchoring a pattern to a line, you need this.
Dot matches newline lets . cross line boundaries. Off by default, because
a pattern like <div>.*</div> with it on will happily swallow your entire
document.
Check before you commit
Matches are counted and highlighted before replacement, so the count is worth a glance: if you expected six and the tool says four hundred, the pattern is broader than you think. Everything runs in the page, so working on a document you should not upload is fine.
questions
- How do I reorder text with find and replace?
- Turn on regex and use capture groups. The pattern (\w+) (\w+), born (\d{4}) with replacement $3: $2, $1 turns 'Ada Lovelace, born 1815' into '1815: Lovelace, Ada'. Each bracketed group is available as $1, $2 and so on.
- What does the multiline flag change?
- It changes what the anchors mean. With multiline on, ^ and $ match the start and end of each line; with it off they match only the start and end of the whole text. You need it on to anchor a pattern to a line.
- Why does my pattern match far more than expected?
- Usually the dot-matches-newline flag combined with a greedy quantifier. A pattern like <div>.*</div> will swallow the whole document once the dot can cross line breaks. The match count is shown before you replace, so a surprising number is a warning.
- Does ignore case adapt the replacement text?
- No. Matching ignores capitalisation but the replacement is inserted exactly as typed, so replacing 'cat' with 'dog' turns 'Cat' into 'dog' rather than 'Dog'.
- Can I use it on text I should not upload?
- Yes. Matching and replacing both run in your browser and nothing is transmitted, so working on a confidential document is fine.