Regex Tester
Test Python regular expressions against sample text.
About Regex Tester
Regex Tester: Try a Pattern Against Sample Text
Enter a regular expression and a test string, then pick match, search or findall. The tool runs the pattern with Python's regex module in its re-compatible mode and prints what it matched.
The three operations
- match: tries the pattern at the very start of the string only.
\d+againstabc 123finds nothing. - search: scans the whole string and returns the first match. The same test returns
123. - findall: returns every non-overlapping match, separated by commas. With capture groups it still shows the full match, not the groups.
Which flavor this is
Patterns follow Python syntax. Most of it carries over to JavaScript, PCRE (PHP), Java and .NET, but a few things differ:
- Named groups: Python writes
(?P<year>\d{4}). JavaScript and .NET use(?<year>...), which theregexmodule also accepts. - Flags: the form has no flag checkboxes. Put them inline at the start of the pattern:
(?i)for case-insensitive,(?m)so^and$match at each line,(?s)so.matches newlines. - Extras: the
regexmodule supports Unicode properties like\p{L}, atomic groups(?>...)and possessive quantifiersa++. Python's built-inreadded the last two in 3.11 but still lacks\p{...}. JavaScript supports\p{L}only with theuflag. - No delimiters: enter
\d+, not/\d+/g.
Quick examples
- Email-like strings:
[\w.+-]+@[\w-]+\.[\w.]+ - IPv4 addresses (loose):
\b(?:\d{1,3}\.){3}\d{1,3}\b - ISO dates:
\d{4}-\d{2}-\d{2}
Limits
Patterns are capped at 1,000 characters and test strings at 100,000. A run that takes longer than 2 seconds gets stopped. That usually means catastrophic backtracking from nested quantifiers such as (a+)+$. Rewrite the pattern so each part can match the text only one way.