Regex Tester
Test and validate regular expressions using .NET's System.Text.RegularExpressions
Match Details
. Any character\d Digit [0-9]\w Word char [a-zA-Z0-9_]\s Whitespace^ Start of string$ End of string
* 0 or more+ 1 or more? 0 or 1{n,m} n to m times() Capture group[] Character class
What Are Regular Expressions?
Regular expressions (regex or regexp) are sequences of characters that define search patterns for text matching, validation, and manipulation. They are supported by virtually every programming language and text editor. Originally developed in the 1950s by mathematician Stephen Kleene, regex has become an indispensable tool for developers working with text data.
Regex Syntax Quick Reference
| Pattern | Meaning | Example |
|---|---|---|
. | Any character except newline | a.c matches "abc", "a1c" |
\d | Any digit (0-9) | \d{3} matches "123" |
\w | Word character (letters, digits, _) | \w+ matches "hello_123" |
\s | Whitespace character | \s+ matches spaces and tabs |
* | Zero or more of the preceding element | ab*c matches "ac", "abc", "abbc" |
+ | One or more of the preceding element | ab+c matches "abc", "abbc" |
? | Zero or one of the preceding element | colou?r matches "color", "colour" |
{n,m} | Between n and m repetitions | \d{2,4} matches 2-4 digits |
[abc] | Character class — any of a, b, or c | [aeiou] matches vowels |
^ / $ | Start / end of string | ^Hello matches "Hello world" |
() | Capture group | (\d{3})-(\d{4}) captures area code and number |
| | Alternation (OR) | cat|dog matches "cat" or "dog" |
Regex Flags
g(global): Find all matches, not just the first one.i(case-insensitive): Match letters regardless of case.m(multiline):^and$match the start/end of each line, not just the entire string.s(dotAll):.also matches newline characters.
Common Use Cases
- Input Validation: Validate email addresses, phone numbers, ZIP codes, URLs, and dates.
- Search & Replace: Find and replace patterns in text files, code, and databases.
- Data Extraction: Parse log files, extract fields from unstructured text, scrape web content.
- Routing: Web frameworks use regex to match URL patterns to controllers/handlers.
- Lexical Analysis: Tokenize source code in compilers, interpreters, and syntax highlighters.
Frequently Asked Questions
Are regex patterns the same across all languages?
Most regex engines share a common syntax, but there are dialect differences. JavaScript, Python, Java, .NET, and PCRE each have slight variations in supported features (e.g., lookbehind, named groups, Unicode support). This tester uses the .NET regex engine.
Can regex validate email addresses?
A basic regex can validate common email formats, but fully validating all RFC 5322-compliant emails requires an extremely complex pattern. For production use, combine a simple regex check with actual email verification (sending a confirmation link).