RegEx Tester

Test regular expressions with real-time matching and highlighting

Regular Expression
Enter your regex pattern and flags
//

Flags: g (global), i (case-insensitive), m (multiline), s (dotAll)

Test String
Enter text to test against your pattern

What are Regular Expressions?

Regular expressions (regex or regexp) are patterns used to match character combinations in strings. They provide a powerful and flexible way to search, validate, and manipulate text. Regular expressions are supported in most programming languages and text editors, making them an essential tool for developers working with text processing, data validation, and pattern matching.

Common Regex Patterns

Character Classes
. - Any character except newline
\\d - Any digit (0-9)
\\w - Any word character (a-z, A-Z, 0-9, _)
\\s - Any whitespace character
Quantifiers
* - 0 or more times
+ - 1 or more times
? - 0 or 1 time
{n,m} - Between n and m times
Anchors
^ - Start of string/line
$ - End of string/line
\\b - Word boundary
\\B - Not a word boundary
Groups & Ranges
(abc) - Capture group
[abc] - Character set (a, b, or c)
[^abc] - Negated set (not a, b, or c)
(a|b) - Alternation (a or b)

Frequently Asked Questions

What do the regex flags mean?
g (global): Find all matches instead of stopping after the first. i (case-insensitive): Match both uppercase and lowercase. m (multiline): ^ and $ match start/end of lines, not just the string. s (dotAll): . matches newline characters. u (unicode): Enable full Unicode support. y (sticky): Match only from lastIndex position.
How do I escape special characters?
Use a backslash (\\) before special characters: . * + ? ^ $ { } [ ] ( ) | \. For example, to match a literal period, use \\. instead of just a dot. To match a backslash itself, use \\\\.
What's the difference between greedy and lazy matching?
Greedy quantifiers (* + {n,m}) match as much as possible. Lazy quantifiers (*? +? {n,m}?) match as little as possible. For example, in "<div>text</div>", <.*> matches the entire string (greedy), while <.*?> matches just <div> (lazy).
How do capturing groups work?
Parentheses ( ) create capturing groups that save matched text for later use. For example, (\\d3)-(\\d4) in "555-1234" captures "555" and "1234" separately. Non-capturing groups (?:...) match but don't save the result.
Can regex validate email addresses perfectly?
No perfect regex exists for email validation because the RFC 5322 standard is extremely complex. Simple patterns like [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,} work for most cases but miss edge cases. For production, use dedicated email validation libraries that check both syntax and MX records.
Why isn't my regex matching multiline text?
By default, ^ and $ only match the start/end of the entire string. Enable the 'm' (multiline) flag to make them match the start/end of each line. Also, . doesn't match newlines by default—use the 's' (dotAll) flag or [\\s\\S] to match any character including newlines.

Related Developer Tools