Skip to main content

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.

Loading tool...

Steps

1

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.

2

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.

3

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.

4

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.

5

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

Related Tools