TASK
Find and replace text using a regular expression
Search for patterns (not just literal strings) in text and replace matches with a template that can reference capture groups.
- 1
Regex find-and-replace goes beyond literal substitution: it matches patterns (all email addresses, all numbers, repeated whitespace) and can use captured submatches in the replacement (e.g. swap first and last name).
- 2 Regex Replace →
Enter the regex pattern, flags (g for global, i for case-insensitive), and replacement template (use $1, $2 for capture groups). The tool shows all matches and the replaced output.
- 3 Regex Tester →
Test the pattern first in the regex tester to confirm it matches what you expect before applying the replacement — this avoids catastrophic replacements on unexpected input.
Frequently asked questions
- What is the difference between $1 and \1 in replacement?
- $1 is the JavaScript replacement syntax; \1 is the sed/Perl syntax. Use $1 in JS-based tools. Named capture groups can be referenced as $<name> in modern JS.
- My regex is too greedy — how do I limit matches?
- Use non-greedy quantifiers (*?, +?) to match the shortest possible string, or replace .* with more specific character classes. Always test on edge cases — greedy regex is the most common source of unexpected replacements.
Workflows that solve this
Learn more
Want to understand why?
How to Debug Regular Expressions
An intermediate-level guide covering regex, debug, text. Includes step-by-step instructions, common errors, troubleshooting tips, and security considerations for regex. TUTORIAL
How to Optimize Regular Expressions
An advanced-level guide covering regex, optimization, performance. Includes step-by-step instructions, common errors, troubleshooting tips, and security considerations for regex. TUTORIAL
Regular Expression
A regular expression is a formal language for describing string patterns, defining matching rules with metacharacters and quantifiers; it is widely used for search, validation, and extraction. GLOSSARY
Buffer Overflow
A buffer overflow occurs when a program writes more data into a fixed-size buffer than it can hold, overwriting adjacent memory and potentially causing crashes or code execution. GLOSSARY
Related tools
Regex Replace
Find and replace text using regular expressions. Free, private, 100% client-side. TOOL
Regex Tester
Test regular expressions with match highlighting, capture groups, and replace preview. Free, private, and 100% client-side. TOOL
Case Converter
Convert text between upper, lower, title, camel, pascal, snake, kebab, constant, and sentence cases. Free, private, and 100% client-side. TOOL