Python Regex Engine with Recursive Backtracking

Just shipped a tiny regex engine in Python from scratch. 🎯 It supports literals, . wildcards, and the * operator using a recursive backtracking matcher, plus a full test suite and docs so you can see exactly how it works under the hood. I also wrapped it in some creative worldbuilding around “Pattern Keys” — forbidden codes that unlock hidden meaning in text — because learning hits different when you mix algorithms with imagination. This project was a deep dive into how regex engines actually work, how backtracking behaves in practice, and how to design clean, readable code instead of “magic.” What’s one algorithm you think every engineer should implement at least once? 👇 https://buff.ly/zY2K4yZ #Python #Regex #Algorithms #Coding #SoftwareEngineering #CreativeCoding #Backtracking

For anyone who wants the technical breakdown + repo, here’s what this tiny regex engine does. Core features matches(pattern, text): Boolean matcher with literals, ., and * using recursive backtracking. find_all_matches(pattern, text): Returns all substrings that match the pattern. Handles edge cases (empty strings, non-ASCII) with a 13-test unittest suite. How it works Recursive matcher that can advance or branch when * appears. * is greedy: it consumes as much as possible, then backtracks to satisfy the rest of the pattern. Implemented in pure Python, no re or external libs. Why I built it To understand regex engines instead of treating them as black boxes. To practice reasoning about backtracking and failure paths. To tie it into a “Pattern Keys” concept: forbidden codes that unlock hidden structure in text. GitHub repo: https://github.com/KyPython/pattern-keys-regex

Like
Reply

To view or add a comment, sign in

Explore content categories