Regex Tester
Runs in browserTest and debug regular expressions
How to Use
Test regex patterns against a string.
Common Flags:
- g: Global (find all matches)
- i: Case-insensitive
- m: Multiline mode
Matches (0)
No matches yet
Enter a pattern and test string to find matches
About Regular Expressions
Regular expressions (regex) are patterns used to match character combinations in strings. They're essential for text searching, validation, parsing, and transformation across all programming languages.
Basic Syntax
- .
- Any character except newline
- *
- Zero or more of the preceding
- +
- One or more of the preceding
- ?
- Zero or one of the preceding
- ^
- Start of string/line
- $
- End of string/line
- [abc]
- Character class: a, b, or c
- [^abc]
- Negated class: not a, b, or c
- (group)
- Capturing group
- a|b
- Alternation: a or b
Character Classes
- \d
- Digit [0-9]
- \D
- Non-digit [^0-9]
- \w
- Word character [A-Za-z0-9_]
- \W
- Non-word character
- \s
- Whitespace (space, tab, newline)
- \S
- Non-whitespace
- \b
- Word boundary
Common Regex Patterns
Email Validation
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Phone Number (US)
^\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}$URL
https?:\/\/[^\s/$.?#].[^\s]*IP Address (IPv4)
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$Regex Flags
- g
- Global — find all matches
- i
- Case-insensitive
- m
- Multiline — ^ and $ match line breaks
- s
- Dotall — . matches newlines
- u
- Unicode mode
Regex in Code
JavaScript
// Test if matches
/\d+/.test("123") // true
// Find all matches
"a1b2c3".match(/\d/g) // ["1", "2", "3"]
// Replace
"hello".replace(/l/g, "L") // "heLLo"Python
import re
re.search(r'\d+', 'abc123') # Match object
re.findall(r'\d', 'a1b2c3') # ['1', '2', '3']
re.sub(r'l', 'L', 'hello') # 'heLLo'💡 Pro Tips
- Start simple and add complexity gradually
- Use non-greedy quantifiers (
*?,+?) when needed - Escape special characters with backslash:
\.,\* - Use named groups for readability:
(?<name>pattern) - Test thoroughly — regex edge cases are common bugs
Further Reading
- MDN: Regular Expressions - Complete JavaScript regex guide.
- Regular-Expressions.info - In-depth tutorials and reference.