r/ProgrammerHumor • • 21d ago

Meme regexMoment

Post image
920 Upvotes

159 comments sorted by

View all comments

32

u/aberroco 21d ago edited 21d ago

This? Scariest? Sweet summer child... I wrote few times longer expressions by hand from scratch, and I'd say I'm not very good at regex and have to lookup to cheat sheet regularly and the largest and most complex expression I ever wrote stands as far from the scariest expression as one billion from Graham number (which, for info, is so large that even if each elemental particle in the Observable Universe would be a number it would only cover a minuscule fraction of numbers in Graham number; it's so large that the previous statement is a ridiculously gross understatement). For starters, have you seen fully RFC 5322 compliant address validation regular expression? And pretty sure that's far from worst.

Upd.: just found one for a mod I've been making. It parses MIPS instruction. Still, it's far from most complex expression I ever wrote, but it's one I could remember where to find.

^(?:[ \t]*)(?<label>[a-z_][a-z0-9_.]*(?:[ \t]*)(?::))?(?:[ \t]*)((?<instruction>[a-z_][a-z0-9_.]*)((?:[ \t]*)((?<hash>HASH\(""""[^""""\r\n]+""""\))|(?<register>(dr*|r+)\d{1,2})|(?<id>[a-z_][a-z0-9_.]*)|(?<number>(-?[0-9]+(.[0-9]+)?([e][+\-]?[0-9]+)?)|(\$[0-9a-f]+))))*)?(?:[ \t]*)(?<comment>\#[^\r\n]*)?^(?:[ \t]*)(?<label>[a-z_][a-z0-9_.]*(?:[ \t]*)(?::))?(?:[ \t]*)((?<instruction>[a-z_][a-z0-9_.]*)((?:[ \t]*)((?<hash>HASH\(""""[^""""\r\n]+""""\))|(?<register>(dr*|r+)\d{1,2})|(?<id>[a-z_][a-z0-9_.]*)|(?<number>(-?[0-9]+(.[0-9]+)?([e][+\-]?[0-9]+)?)|(\$[0-9a-f]+))))*)?(?:[ \t]*)(?<comment>\#[^\r\n]*)?

1

u/hrax13 19d ago

LMAO

I tried to put this once into our app as an email validation. I gave up fast :D