Regex Tester
Test and debug regular expressions with real-time match highlighting, capture groups, and find-and-replace.
Test Regular Expression
How to Use This Regex Tester
Step 1: Enter your regular expression pattern in the Pattern field at the top. The tool validates your regex in real time and will show an error if the syntax is invalid.
Step 2: Select the flags you need: g (global — find all matches), i (case-insensitive), m (multiline — makes ^ and $ match line boundaries), or s (dotAll — makes . match newlines).
Step 3: Paste or type your test text in the text area below. Matches are highlighted instantly as you type. The match info panel shows the total number of matches, their positions, and any capture groups.
Step 4: Switch to the Replace tab to test find-and-replace operations. Enter a replacement string using $1, $2 to reference capture groups, and see the result live.
Regex Syntax Quick Reference
Character classes: \d matches any digit, \w matches word characters (letters, digits, underscore), \s matches whitespace. Use uppercase (\D, \W, \S) for the inverse. Custom character classes use brackets: [aeiou] matches any vowel, [^0-9] matches any non-digit.
Quantifiers: * matches zero or more, + matches one or more, ? matches zero or one. Use {n} for exactly n occurrences, {n,m} for between n and m. Add ? after any quantifier to make it lazy (match as few as possible).
Anchors and boundaries: ^ matches the start of a line, $ matches the end. \b matches a word boundary — essential for matching whole words without partial matches. For example, \bcat\b matches "cat" but not "category".
Groups and lookaround: () creates a capture group. (?:) is a non-capturing group. (?=...) is a positive lookahead, (?!...) is a negative lookahead, and (?<=...) is a positive lookbehind.
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,$2in 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\banchor matches the boundary between a word character and a non-word character.