Regex Tester
Build and test regular expressions with real-time feedback and highlighting.
/
/gm
Use $1, $2, etc. to reference captured groups. Use $& to reference the entire match.
Enter a regular expression to see matches
Regular Expression Reference
Regular expressions (regex) are patterns used to match character combinations in strings. They are powerful tools for text processing, validation, and search operations.
Basic Syntax
Character Classes
.
- Any character except newline\w
- Word character [a-zA-Z0-9_]\d
- Digit [0-9]\s
- Whitespace character[abc]
- Any of a, b, or c[^abc]
- Not a, b, or c[a-z]
- Any character a through z
Quantifiers
*
- 0 or more, equivalent to {0,}+
- 1 or more, equivalent to {1,}?
- 0 or 1, equivalent to {0,1}{3}
- Exactly 3 times{3,}
- 3 or more times{3,5}
- Between 3 and 5 times
Anchors
^
- Start of string/line$
- End of string/line\b
- Word boundary\B
- Not word boundary
Groups & Alternation
(abc)
- Capture group(?:abc)
- Non-capturing groupa|b
- Match a or b(?<name>abc)
- Named capture group
Common RegEx Patterns
Email Address
^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$
URL
https?:\/\/[\w\d\-\.]+\.\w{2,}[\w\d\-\.\/\?\=\&\%]*
IPv4 Address
\(?:\d{1,3}\.){3}\d{1,3}\
ISO Date
\d{4}-\d{2}-\d{2}
Regex Best Practices
- Start simple and build complexity incrementally
- Use non-capturing groups (?:) when you don't need the captured value
- Be careful with greedy quantifiers (* and +) which can lead to unexpected results
- Test with various inputs, including edge cases
- Consider performance implications for large inputs