regex-le 0.3.1

Find every regex in a codebase, and report which can be driven into catastrophic backtracking
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import re

# The textbook catastrophic-backtracking shape, in a raw string
NESTED = re.compile(r"(a+)+")

# A quoted string escapes a level, exactly as the JS constructor does
ESCAPED = re.compile("\\d{3}-\\d{4}")

# Single-quoted raw, and a triple-quoted body
SINGLE = re.match(r'^[a-z]+$', name)
TRIPLE = re.search("""(a|ab)+""", text)

# A path is not a pattern: Python has no /…/ literal
PREFIX = "/usr/local/bin"