Find and Replace

Find and replace text with support for regular expressions and case sensitivity.

About This Tool

Performs find-and-replace across pasted text with optional regular-expression matching, case sensitivity, and whole-word boundaries. Regex flavor is JavaScript's built-in (ECMAScript 2018+), supporting groups, lookaheads, and Unicode property escapes.

Replacement strings can include capture group references ($1, $2) for restructuring matched text.

The regex implementation uses JavaScript's native RegExp engine, which differs in subtle but consequential ways from Perl-compatible regex (PCRE), Python's re module, and Go's RE2. JavaScript regex follows ECMAScript 2018+ specification: it supports named capture groups (?<name>...), lookbehind assertions ((?<=...) and (?<!...)) since ES2018, Unicode property escapes (\p{Letter}, \p{Emoji}) with the u flag, and the s flag for dot-matches-newline. It does not support atomic groups, possessive quantifiers, or recursive patterns (which PCRE allows). For most practical text manipulation these omissions don't matter; for parsing complex nested structures, a proper parser is the right tool.

A worked example: matching email addresses with a moderately strict pattern. The regex /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g matches common email formats. Replacing all matches with '[REDACTED]' anonymizes log files. Capturing local-part and domain separately with /(\w+)@([\w.]+)/g and replacing with '$2 user $1' restructures 'alice@example.com bob@example.org' into 'example.com user alice example.org user bob'. The capture group syntax ($1, $2 for numbered groups; $<name> for named) provides the restructuring power that makes regex replace more useful than literal string replace.

Limitations and pitfalls are the regex classics. Catastrophic backtracking can hang the browser tab on pathological patterns: the canonical example is /^(a+)+$/ applied to 'aaaaaaaaaaaaaaaaX', which causes the engine to try every possible partition of the a's before failing. Modern regex engines (V8, Spidermonkey, JavaScriptCore) include some protection against this for common patterns but do not guarantee linear-time matching. The greedy-vs-lazy distinction (.* vs .*?) is the source of many silent bugs; .* matches as much as possible and is rarely what you want when matching between delimiters. Anchors (^ and $) interact with the multiline flag in non-obvious ways; without /m, ^ matches only the very start of input.

Unicode handling improved significantly with ES2018. Without the u flag, JavaScript regex treats characters as 16-bit UTF-16 code units, splitting emoji and other supplementary-plane characters into surrogate pairs that the regex engine sees as separate characters. With /u, characters are treated as code points, and escapes like \u{1F600} (grinning face) work correctly. For any modern text processing, /u should be considered the default. The Unicode property escapes (\p{Script=Latin}, \p{Number}) replace much of the manual character-class building that older regex required.

The about text and FAQ on this page were drafted with AI assistance and reviewed by a member of the Coherence Daddy team before publishing. See our Content Policy for editorial standards.

Frequently Asked Questions