How to use it

  1. Type a pattern (without surrounding /.../ slashes) and toggle flags: g (all matches), i (ignore case), m (multiline ^/$), and s (dotall, so . matches newlines).
  2. Paste the text or HTML snippet you want to extract from, or click one of the scraping presets.
  3. Inspect each match and its numbered/named capture groups, then copy the equivalent Python re code.

Common mistakes

  • Using greedy .* between tags or quotes. Prefer .*? or negated classes like [^"']+ so a match stops at the first delimiter.
  • Forgetting raw strings in Python. Always write r"..." in Python so \d, \b, and \s are not interpreted as string escapes.
  • Using regex instead of CSS/XPath for DOM structure. Parse HTML with BeautifulSoup or lxml first, then run regex on the extracted text.

FAQ

Should I use regex to parse HTML?

Use a real HTML parser (BeautifulSoup, lxml, CSS/XPath) to locate elements, then use regex to clean or extract structured values like prices, dates or IDs from inside the text or script tags.

Are JavaScript and Python regexes identical?

They share most syntax (character classes, quantifiers, lookahead/lookbehind, named groups). Python uses (?P<name>...) for named groups, whereas JavaScript uses (?<name>...).

What do the i, m and s flags do?

i ignores case (re.IGNORECASE), m makes ^ and $ match line boundaries (re.MULTILINE), and s makes . match newlines too (re.DOTALL).

Why do lazy quantifiers (*?, +?) matter when scraping?

Greedy .* matches as much text as possible up to the last closing delimiter on a line; .*? stops at the first match, which is almost always what you want.

What is catastrophic backtracking?

Nested quantifiers like (a+)+ can take exponential time on non-matching input. Keep patterns specific (e.g. [^"']+ instead of .*) and avoid ambiguous repetition.