Tuesday, September 26, 2017 14:42

Python Regex

I mainly made this as a bet a couple of months ago, but it turned out to be really fun to make and a lot harder than I expected.

Basically it is just a program that functions a lot like sed, but missing a lot of features. I believe it performs regex perfectly (as I have tested it a fair bit) but regex has quite a few quirks so it is likely there is a small bug here or there. It is 429 lines so not a small program at all, but I have rewritten the algorithm like 5 times now so I don’t think I can make it any more compact. Also, error messages are not nice if you mess up your regex ;)


$ echo “hi robin, this is your computer” | ./regex “s/r(\w*?,)/R\$1/” | ./regex “s/i/I/g” | ./regex “s/y(.*?\s)(c)/\$1\$2/”

hI RobIn, thIs Is our computer

$ echo “aaaabcaaabc” | ./regex “m/[abc]+bc/”


$ echo “aaaabcaaabc” | ./regex “m/[^z]+?bc/”


Download it here.

Leave a Reply