Regex Tester — Test and Debug Regular Expressions Online
Our free online regex tester lets you write, test, and debug regular expressions in real time. Matches are highlighted inline as you type, capture groups are shown in distinct colors, and a built-in cheat sheet and common pattern library help you build patterns faster. Switch to Replace mode to test substitutions with backreferences.
Regular Expression Syntax Reference
Character classes and metacharacters
| Pattern | Matches | Example |
|---|---|---|
| . | Any character except newline | c.t matches "cat", "cut", "c3t" |
| \d | Digit 0-9 | \d\d matches "42", "99" |
| \D | Non-digit | \D+ matches "hello", "abc" |
| \w | Word char [a-zA-Z0-9_] | \w+ matches "hello_world" |
| \W | Non-word character | \W matches space, punctuation |
| \s | Whitespace (space, tab, newline) | \s+ matches spaces between words |
| \S | Non-whitespace | \S+ matches any non-space token |
| [abc] | Any of: a, b, c | [aeiou] matches any vowel |
| [^abc] | Not: a, b, c | [^0-9] matches non-digits |
| [a-z] | Range: a through z | [a-zA-Z] matches any letter |
| ^ | Start of string/line | ^Hello matches "Hello world" |
| $ | End of string/line | world$ matches "Hello world" |
| \b | Word boundary | \bcat\b matches "cat" not "catch" |
Quantifiers
| Quantifier | Meaning | Greedy? | Example |
|---|---|---|---|
| * | 0 or more | Yes | ab* matches "a", "ab", "abb" |
| + | 1 or more | Yes | ab+ matches "ab", "abb" not "a" |
| ? | 0 or 1 | Yes | ab? matches "a" or "ab" |
| {n} | Exactly n | — | \d{4} matches "2024" |
| {n,} | n or more | Yes | \d{2,} matches "42", "100" |
| {n,m} | Between n-m | Yes | \d{2,4} matches "42", "100" |
| *? | 0 or more | No (lazy) | a.*?b matches shortest possible |
| +? | 1 or more | No (lazy) | a.+?b matches shortest possible |
Groups and lookarounds
| Syntax | Type | Description |
|---|---|---|
| (abc) | Capture group | Captures and remembers matched text |
| (?:abc) | Non-capturing | Groups without capturing |
| (?<name>abc) | Named group | Capture with a label |
| (?=abc) | Lookahead | Matches if followed by abc |
| (?!abc) | Neg lookahead | Matches if NOT followed by abc |
| (?<=abc) | Lookbehind | Matches if preceded by abc |
| (?<!abc) | Neg lookbehind | Matches if NOT preceded by abc |
Regex flags
| Flag | Name | Effect | Example |
|---|---|---|---|
| g | Global | Find all matches, not just first | /\d+/g finds all numbers |
| i | Case Insensitive | Match regardless of case | /hello/i matches "Hello", "HELLO" |
| m | Multiline | ^ and $ match line start/end | /^\w+/m matches first word of each line |
| s | Dotall | Dot matches newline too | /.+/s matches across lines |
| u | Unicode | Full Unicode matching | /\p{L}+/u matches Unicode letters |
| y | Sticky | Match only from lastIndex | Used for parsing streams |
Common regex patterns
| Use case | Pattern | Notes |
|---|---|---|
| Email validation | ^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,}$ | Basic — full RFC 5322 is much more complex |
| US Phone number | (\+1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} | Handles various formats |
| URL | https?:\/\/[\w-]+(\.[\w-]+)+(\/[\w-./?%&=]*)? | Simplified URL match |
| HEX color | #([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}) | 3 or 6 digit hex |
| IP address | \b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b | Simplified — use full pattern for validation |
| Date YYYY-MM-DD | \d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) | With basic month/day validation |
| ZIP code (US) | ^\d{5}(-\d{4})?$ | 5 digit or ZIP+4 |
Greedy vs lazy matching — key difference
One of the most important concepts in regex is the difference between greedy and lazy quantifiers. This determines how much text a quantifier tries to consume:
Consider the string: <b>Hello</b> and <b>World</b>
Greedy: <b>.*</b> matches the entire string from the first <b> to the last </b> — consuming everything in between.
Lazy: <b>.*?</b> matches <b>Hello</b> and <b>World</b> separately — stopping at the first possible </b>.
In most HTML parsing and text extraction scenarios, lazy quantifiers give the intended result.
Regex in different programming languages
| Language | Regex syntax | Test method | Match method |
|---|---|---|---|
| JavaScript | /pattern/flags or new RegExp() | regex.test(str) | str.match(regex) |
| Python | re module, r"pattern" | re.match() or re.search() | re.findall() |
| Java | Pattern.compile("pattern") | matcher.matches() | matcher.find() |
| PHP | preg_match("/pattern/", $str) | preg_match() | preg_match_all() |
| C# | Regex.IsMatch("pattern") | Regex.IsMatch() | Regex.Matches() |
| Ruby | /pattern/ or Regexp.new | str =~ /pattern/ | str.scan(/pattern/) |
| Go | regexp.MustCompile("pattern") | regexp.MatchString() | re.FindAllString() |
Frequently asked questions
How do I match a literal dot in regex?
In regex, a dot (.) is a metacharacter that matches any character except a newline. To match a literal dot, escape it with a backslash: . For example, to match "example.com" use example\.com rather than example.com(which would also match "exampleXcom").
How do I make a regex case insensitive?
Add the "i" flag to your regex. In JavaScript: /hello/imatches "Hello", "HELLO", "hElLo" and any other case combination. Toggle the "i" flag chip in this tester to enable case-insensitive matching.
What does \b mean in regex?
\b is a word boundary assertion. It matches the position between a word character (\w) and a non-word character (\W). For example, \bcat\bmatches the word "cat" in "the cat sat" but NOT in "catch" or "concatenate", because in those words "cat" is not surrounded by word boundaries.
How do I match multiple lines in regex?
Use the "m" (multiline) flag to make ^ and $ match the start and end of each line rather than just the start and end of the entire string. Use the "s" (dotall) flag to make the dot (.) also match newline characters, allowing patterns to span multiple lines.
How do I extract text from between tags using regex?
Use a capture group with a lazy quantifier: <tag>(.*?)</tag> captures the content between the tags. The lazy *? ensures the match stops at the first closing tag rather than consuming everything to the last closing tag. For production HTML parsing, always use a proper HTML parser rather than regex.