Just pop them into regex101 or a similar tool, add sample data, see the mistake, fix the mistake, continue to do other stuff.
Programmer Humor
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
Just pop them into regex101 or a similar tool, add sample data, ~~see the mistake, fix the mistake, continue to do other stuff.~~ it works there, pull hair
FTFY
I usually do
# What we are doing (high level)
# Why we need regex
# Regex step by step
# Examples of matches
regex
And I still rewrite it the next time
// abandon all hope ye who commit here
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
Edith: damit, Not the first to post this abomination
I haven't laughed so hard in a month. Thank you for that.
Downvoted so that everyone can know I'm cool since I understand regex better than the idiot who made that meme.
I know I'm weird, but I love regex.
Me checking my own docs: "this is some voodoo shit, idk how it works"
That's what my comments say
After fixing, now that you are expert, please migrate the regex to our new language.
Others: "Oh god, regexes are so hard to understand!"
Me, an intellectual: writing a code that does the same.
LOL yeah that's about right.
Aziz! LIGHT!
awk-ward
There are no bugs, it's just not doing what you expect it to be doing...
... which, now that I think of it, can be said about all software in general.
Ffs just rewrite it
Elisp has a nice notation for maintainably composing regexes like any other programming expression.
Only language I've seen offer that.
So instead of "/\\*\\(?:[^*]\\|\\*[^/]\\)*\\*+/"
, the regular expression to match C block comments could be expressed (with inline comments)
(rx "/*" ; Initial /*
(zero-or-more
(or (not (any "*")) ; Either non-*,
(seq "*" ; or * followed by
(not (any "/"))))) ; non-/
(one-or-more "*") ; At least one star,
"/") ; and the final /