Regex Tester

Test and debug regular expressions with real-time match highlighting, capture groups, and find-and-replace.

🔍 Test Regular Expression

Pattern
Test String
Highlighted Matches
Replacement String
Replaced Output

How to Use Regular Expressions

A regular expression (regex) is a pattern that describes a set of strings. Regex is used in virtually every programming language for text search, input validation, find-and-replace, and data extraction. To use this tool, enter a pattern, select your flags, and type or paste the text you want to test against. Matches are highlighted in real time.

Flags modify how the pattern is applied: g (global) finds all matches; i (case-insensitive) ignores case; m (multiline) makes ^ and $ match line boundaries; s (dotAll) makes . match newlines.

The Replace tab lets you test substitutions. Use $1, $2, etc. to reference capture groups in the replacement string. For example, the pattern (\w+)@(\w+) with replacement $2/$1 would transform user@domain into domain/user.

Common Regex Patterns

Email: [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} — matches most standard email formats.
URL: https?://[^\s/$.?#].[^\s]* — matches HTTP and HTTPS URLs.
Phone (US): \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} — matches common US phone number formats.
IPv4: \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b — matches IP addresses.
Whole word: \bword\b — use word boundaries to match exact words without partial matches.

Frequently Asked Questions

What is a regular expression?
A regex is a pattern of characters used to match, search, and manipulate text. It's supported in virtually every programming language and is essential for validation, parsing, and text processing.
How do I test a regex online?
Enter your pattern above, select flags (g, i, m, s), and paste test text. Matches are highlighted in real time with positions and capture groups shown.
What are capture groups?
Text enclosed in () that captures the matched substring for later reference. Use $1, $2 in replacement strings. Named groups use (?<name>...) syntax.
What does the g flag do?
The g (global) flag finds all matches in the string instead of stopping at the first match. Most find-and-replace operations require this flag.
How do I match a whole word?
Use word boundary anchors: \bword\b. This matches “word” but not “sword” or “wordy”. The \b anchor matches the boundary between a word character and a non-word character.