Ken Thompson's regex-to-NFA construction, which you are implementing a subset of, underlies grep, RE2, and the lexer generators flex and re2c. Understanding it explains both why RE2 is immune to catastrophic backtracking and why PCRE is not — a distinction that has caused real outages, including Cloudflare's 2019 global outage from a backtracking regex.