this post was submitted on 14 Feb 2025
888 points (98.5% liked)

Programmer Humor

20689 readers
784 users here now

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

founded 2 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 24 points 6 days ago (1 children)

Just pop them into regex101 or a similar tool, add sample data, see the mistake, fix the mistake, continue to do other stuff.

[–] [email protected] 3 points 4 days ago

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

[–] [email protected] 22 points 6 days ago (1 children)

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

[–] [email protected] 18 points 6 days ago* (last edited 6 days ago) (2 children)
// 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

[–] [email protected] 11 points 6 days ago

Downvoted so that everyone can know I'm cool since I understand regex better than the idiot who made that meme.

[–] [email protected] 9 points 6 days ago

I know I'm weird, but I love regex.

[–] [email protected] 15 points 6 days ago (1 children)

Me checking my own docs: "this is some voodoo shit, idk how it works"

[–] [email protected] 3 points 6 days ago

That's what my comments say

[–] GarlicToast 2 points 4 days ago

After fixing, now that you are expert, please migrate the regex to our new language.

[–] [email protected] 1 points 4 days ago

Others: "Oh god, regexes are so hard to understand!"

Me, an intellectual: writing a code that does the same.

[–] [email protected] 7 points 6 days ago

LOL yeah that's about right.

[–] DrDeadCrash 7 points 6 days ago

Aziz! LIGHT!

[–] [email protected] 3 points 6 days ago
[–] [email protected] 4 points 6 days ago

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.

[–] [email protected] 2 points 6 days ago

Ffs just rewrite it

[–] [email protected] 2 points 6 days ago* (last edited 6 days ago)

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 /
load more comments
view more: next ›