Regex Find and Replace
Switch to Replace to preview a native JavaScript replacement on your sample text. The opening example replaces both colour words with color using g. Remove g to replace only the first occurrence. Edit the pattern, flags, replacement or text and copy the current output; obsolete results cannot be copied while another run is pending.
$& keeps the match, $1 to $99 keep numbered groups, $<name> keeps a named group, and $$ inserts a dollar sign. Type an actual newline for a line break. Without g only the first match is replaced.
Matching.
Replaced text
Replacing.
- Matches
- -
- Groups
- -
- Flags
- Engine
- JavaScript
Matching.
d record where each match starts and ends · g find every match, not only the first · i ignore upper and lower case · m ^ and $ match at every line · s a dot also matches a newline · u read the text as unicode code points · v unicode sets, with set operations in classes · y match only where the last one left off
- both, with offsets
- listed by name
- stopped by timeout
Common questions
- How do I replace every match?
- Include g in the flags. JavaScript string replacement without g replaces the first match only. Case-insensitive replacement uses i as well.
- What happens when there is no match?
- The output remains the original text and the replacement count is zero. An empty replacement removes matching text; it does not mean no operation.
- Does this replace text in a file or editor?
- It previews pasted text in your browser. It does not modify a filesystem, editor project, database or another application.
Matching uses your browser's own JavaScript regular expression engine, so what you see here is what your code will do. It runs in a disposable worker with a timeout, so a pattern that would hang the page is stopped and reported instead.