How to Test Regular Expressions Online
Test and debug regular expressions in real time with our free Regex Tester. See matches highlighted instantly with explanation of each match group.
Steps
Enter your regular expression
Type or paste your regex pattern into the pattern field. Do not include the surrounding slashes — enter just the pattern itself, for example: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$. Flags like global (g), case-insensitive (i), and multiline (m) are set separately.
Set flags
Choose which flags to apply. The most common are: g (global) to find all matches rather than stopping at the first; i (case-insensitive) to match regardless of letter case; m (multiline) to make ^ and $ match the start and end of each line rather than the whole string.
Paste your test string
Enter the text you want to match against in the test string area. You can use multiple lines of text. All matches will be highlighted in the text as you type, giving you immediate visual feedback.
Review match groups
The match details panel shows each capture group's matched value, its position (start and end index), and the full match. If your regex uses named groups (?P<name>pattern) or (?<name>pattern), the group names appear in the results.
Iterate and refine
Adjust your pattern based on what matched and what did not. Common issues include unescaped special characters (. matches any character; use \. to match a literal dot), greedy vs lazy quantifiers, and anchoring problems. The live feedback loop makes iteration fast.
Understanding Regular Expression Syntax
Regular expressions are a domain-specific language for describing text patterns. They are built from three types of elements: literals (characters that match themselves, like abc), metacharacters (characters with special meaning, like . * + ?), and constructs (grouping, alternation, and anchoring). Character classes [abc] match any of the listed characters. Ranges [a-z] match any character in the range. Negated classes [^abc] match anything except the listed characters. Quantifiers control repetition: * means zero or more, + means one or more, ? means zero or one, {n} means exactly n times, {n,m} means between n and m times. Anchors ^ and $ assert position at the start or end of a string. Groups () capture matched text for later use or for applying quantifiers to a sequence.
Common Regex Use Cases and Patterns
Regex is used pervasively in programming for input validation, text parsing, and search-and-replace operations. Email validation: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$. URL matching: https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}. Date format (YYYY-MM-DD): ^\d{4}-\d{2}-\d{2}$. Phone numbers are notoriously variable — use a library like libphonenumber for production use. IP addresses: ^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(...). Hex colour codes: ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$. Extracting content between tags: <tag>(.*?)<\/tag> with the lazy quantifier and capturing group.
Performance Considerations with Regular Expressions
Most regex patterns run in microseconds, but poorly written expressions can trigger catastrophic backtracking — a condition where the regex engine tries exponentially many combinations before determining there is no match. This is called ReDoS (Regular Expression Denial of Service) and has caused real outages. The patterns most vulnerable to catastrophic backtracking involve nested quantifiers like (a+)+ or alternation with overlapping options like (a|aa)+. When writing regex for production use, test with strings that should not match as well as strings that should — a slow non-match is a red flag. Use atomic groups or possessive quantifiers when your regex flavour supports them to prevent backtracking. For complex parsing tasks where performance matters, consider dedicated parsing libraries instead of regex.
Frequently Asked Questions
The default flavour is JavaScript (ECMAScript) regex, which is the standard for browser-based tools. You can switch to PCRE (PHP, Python, Perl) mode or Python re module mode using the flavour selector. Different flavours handle lookaheads, lookbehinds, named groups, and Unicode differently, so always test in the flavour matching your runtime.
Escape special characters with a backslash: \. matches a literal dot, \* matches a literal asterisk, \( and \) match literal parentheses. The characters that need escaping in regex are: . * + ? ^ $ { } [ ] | ( ) and \.
Greedy quantifiers (*, +, ?) match as much as possible. Lazy quantifiers (*?, +?, ??) match as little as possible. For example, <.+> on '<b>text</b>' matches the entire string greedily. <.+?> matches '<b>' then '</b>' separately. Use lazy quantifiers when you want to match the shortest possible string between delimiters.
Enable the multiline (m) flag to make ^ and $ match line boundaries rather than the start and end of the entire string. Enable the dotall (s) flag to make the dot (.) match newline characters — useful when your pattern needs to span multiple lines.