HTTPfy

Regex Tester

Test Python regular expressions against sample text.

Action
Regex Tester Ready

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+ against abc 123 finds 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 the regex module 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 regex module supports Unicode properties like \p{L}, atomic groups (?>...) and possessive quantifiers a++. Python's built-in re added the last two in 3.11 but still lacks \p{...}. JavaScript supports \p{L} only with the u flag.
  • 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.