Regex Tester Online Free
Test and debug regular expressions in real time — enter a pattern and test string to see matches highlighted instantly. Supports g, i, m, s flags and capture groups.
⏱ 5 min read · Complete guide below
Regex Tester
How to Use the Regex Tester
- 1Enter your regular expression in the pattern field between the slashes. Toggle the g, i, m, and s flags as needed.
- 2Paste your test string into the text area below. Matches update live as you type.
- 3Each match shows the matched value, its character index, and any capture groups.
- 4If the pattern is invalid, the error message from the JavaScript engine is shown so you can pinpoint the syntax issue.
What Regular Expressions Actually Are
A regular expression is a compact pattern language for describing text. Instead of searching for a fixed string, you describe the shape of what you want — “a run of digits,” “an email-like token,” “anything between two brackets” — and the regex engine finds every piece of text that fits. That makes regex one of the most powerful tools in a programmer's toolkit for searching, validating, extracting, and replacing text: pulling all the URLs out of a document, checking that a form field looks like a phone number, or reformatting dates across a whole file. The core building blocks are character classes (\d for a digit, \w for a word character, . for any character), quantifiers (*, +, {2,4} for how many times something repeats), anchors (^ and $ for the start and end), and groups (parentheses that both organise the pattern and capture the part you want to keep). This tester lets you assemble those pieces and see instantly what they match, which is by far the fastest way to learn them.
Greedy vs Lazy, and Why Regex Sometimes Hangs
One behaviour surprises nearly everyone at first: quantifiers are greedy by default, meaning they grab as much text as they possibly can. The pattern <.+> against <a><b> matches the entire string, not just <a>, because .+ swallows everything and only backtracks enough to let the final > match. Adding a ? makes a quantifier lazy (<.+?>), so it takes as little as possible and returns <a> then <b> separately. Understanding this one distinction fixes a large share of “my regex matches too much” problems. It also connects to a real performance trap: certain patterns with nested quantifiers can trigger catastrophic backtracking, where the engine explores an exponential number of possibilities and appears to hang on some inputs. Testing your pattern here against realistic sample text — including the awkward edge cases — is the simplest way to catch both a too-greedy match and a pathologically slow one before it reaches production.
Common Regex Patterns Reference
The patterns below cover the most frequent use cases. Copy and paste them as a starting point, then adjust for your specific needs.
Useful Regex Patterns
Email Address
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} — matches most standard email addresses. Use with the i flag for case-insensitive matching.
URL
https?:\/\/[^\s/$.?#].[^\s]* — matches http and https URLs. Add the g flag to find all URLs in a block of text.
IP Address (IPv4)
\b(?:\d{1,3}\.){3}\d{1,3}\b — matches IPv4 addresses. Does not validate that each octet is 0–255; use additional logic for strict validation.
Date (YYYY-MM-DD)
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]) — matches ISO 8601 dates with basic month/day range checks.
Hex Colour
#(?:[0-9a-fA-F]{3}{1,2}) — matches 3-digit and 6-digit hex colour codes including the leading hash. Add the i flag for case-insensitive.
Digits Only
^\d+$ — validates that the entire string is digits only. Use with the m flag to apply per-line in multi-line input.
Frequently Asked Questions
What does each regex flag do?
g (global): find all matches instead of stopping at the first one. i (case insensitive): treat uppercase and lowercase as equal — /hello/i matches "Hello", "HELLO", and "hello". m (multiline): make ^ and $ match the start and end of each line rather than the entire string. s (dotAll): make the dot (.) match newline characters (\n, \r) in addition to all other characters — without this flag, . does not match newlines.
What is the difference between a match and a capture group?
A match is the entire substring that the regex matched. A capture group is a sub-portion of the match, created by wrapping part of the pattern in parentheses. For example, the pattern (\d+)-(\d+) applied to "2024-05" produces a full match of "2024-05", group 1 "2024", and group 2 "05". Named groups use the syntax (?<name>pattern) and can be referenced by name instead of index.
What does the "index" mean in the match results?
The index is the zero-based character position in the input string where the match begins. For example, if the input is "hello world" and the regex matches "world", the index is 6 (counting from 0: h=0, e=1, l=2, l=3, o=4, space=5, w=6). This is useful when you need to know where in the string a match occurred, not just what was matched.
Why does my regex work in my code but not here (or vice versa)?
This tester uses JavaScript's built-in RegExp engine. If your code uses a different language (Python, Java, Go, PHP), the regex syntax may differ. Common differences: Python uses (?P<name>) for named groups while JavaScript uses (?<name>); lookaheads and lookbehinds have different support levels; character class shortcuts like \w, \d may behave differently with Unicode; and some engines support possessive quantifiers or atomic groups that JavaScript does not.
How do I match a literal dot, bracket, or other special character?
In regex, these characters have special meaning: . * + ? ^ $ { } [ ] | ( ) \. To match them literally, escape them with a backslash. For example, to match a literal dot use \., to match a literal opening bracket use \[. The pattern 3\.14 matches the string "3.14" exactly (the unescaped 3.14 would also match "3x14").
What are greedy, lazy, and possessive quantifiers?
Greedy quantifiers (*, +, ?) match as much as possible. Lazy quantifiers (*?, +?, ??) match as little as possible. For example, <.+> applied to "<a><b>" with greedy matching returns the whole string "<a><b>"; with lazy matching (<.+?>) it returns "<a>" then "<b>". Possessive quantifiers (*+, ++) prevent backtracking entirely — JavaScript does not support possessive quantifiers, but they are available in Java and PCRE.
Is my test string or pattern sent to a server?
No. The regex engine used here is JavaScript's native RegExp, which runs entirely in your browser. Neither your pattern nor your test string is transmitted anywhere. You can safely test against sensitive log data, production strings, or proprietary content.