315
submitted 8 months ago by mac@programming.dev to c/comics@programming.dev

Hover Text:

Wait, forgot to escape a space. Wheeeeee[taptaptap]eeeeee!

Transcript

[in a yellow box:]
Whenever I learn a new skill I concoct elaborate fantasy scenarios where it lets me save the day.

Megan: Oh no! The killer must have followed her on vacation!
[Megan points to computer.]
Megan: But to find them we'd have to search through 200 MB of emails looking for something formatted like an address!
Cueball: It's hopeless!

Off-panel voice: Everybody stand back.

Off-panel voice: I know regular expressions.

[A man swings in on a rope, toward the computer.]

tap tap
The word PERL! appears in a bubble.

[The man swings away, and the other characters cheer.]

all 27 comments
sorted by: hot top controversial new old
[-] otacon239@feddit.de 33 points 8 months ago

I learned regex in a data entry job when receiving spreadsheets of user info they entered themselves. The number of times I went from a 40-minute by-hand solution to a 30-second one was astounding.

Need to clean up capitalization? Regex.

Need to fix all the phone numbers with dashes in them? Regex.

Need to make sure all the emails are valid? Regex.

So many hours of tedium saved. It really is one of the most powerful tools to have in your back pocket.

[-] UndercoverUlrikHD@programming.dev 37 points 8 months ago

Need to make sure all the emails are valid? Regex.

Hmm...

[-] hemko@lemmy.dbzer0.com 19 points 8 months ago
[-] elvith@feddit.de 16 points 8 months ago

Who's gonna tell them? I'd do it but I'm still busy parsing HTML with regex.... it's working any minute now!

[-] otacon239@feddit.de 2 points 8 months ago

What am I missing? I typically used it as a sanity check and would vet the changes. Never as a one-click modify. Or is there something else I should know about?

[-] Feathercrown@lemmy.world 4 points 8 months ago* (last edited 8 months ago)

This short article has some good examples at the top: https://sigparser.com/developers/email-parsing/regex-validate-email-address/

Basically, you can very easily make a regex to match 99% of email addresses, but technically an email could be something like "!@[124.35.6.72]"

[-] otacon239@feddit.de 6 points 8 months ago

Ah, yeah. It was never meant to be a be all and all. Just something to clean up the complete trash before I started proofreading. Besides, these were emails the customer provided and could easily be changed afterwords. Their fault if we get bad emails in the list ¯\_(ツ)_/¯

[-] Feathercrown@lemmy.world 3 points 8 months ago

This is the way

[-] elvith@feddit.de 1 points 8 months ago* (last edited 8 months ago)

You're completely correct. In practice, it's usually good enough to just check for ".+@.+" or ".+@.+\..+". Why? It's broad enough to allow almost everything and it rejects the most obvious typos. And in the end, the final verification would be to send an email there which contains a link, that one has to click to finalize the signup/change. Even if you had a regex that could filter every possible adress that's possible according to the standard, you still wouldn't know whether it really exists.

[-] dev_null@lemmy.ml 4 points 8 months ago

I wrote a regex that matches 100% of email addresses and had no problems using it. It's ".+@.+"

[-] Feathercrown@lemmy.world 1 points 8 months ago* (last edited 8 months ago)

Meme aside that's what I'd use tbh. Or the ultimate email validation: just sending the signup email and if they typed an invalid email it won't send

[-] pantyhosewimp@lemmynsfw.com 10 points 8 months ago

Looks like we found the intern who coded the check that rejects “trailingunderscoreisallowedyouasshole_@example.com”.

Follow up by tech support successfully emailing me at that address to tell me to use a different email address.

[-] uid0gid0@lemmy.world 4 points 8 months ago

Now do the one where spaces are allowed in the local part as well

[-] anton@lemmy.blahaj.zone 2 points 7 months ago

While email addresses are technically a regular language but I have seen a the regex that takes up a whole page claiming to be the first standard compliant one.

[-] Norodix@lemmy.world 17 points 8 months ago

No I dont do that. Stop asking. That is not me in the picture.

[-] pikasaurX4@lemm.ee 16 points 8 months ago

The image wouldn’t load for me but your transcript was perfect, thank you

[-] mac@programming.dev 11 points 8 months ago

Credit to explainxkcd for that one, their pages are great

[-] SatanicNotMessianic@lemmy.ml 16 points 8 months ago

I’ve been in the industry for about 30 years now, and I still will break out some command line Perl when I need to regex something.

[-] Diplomjodler@feddit.de 4 points 8 months ago* (last edited 8 months ago)

I've never bothered to learn regex because I can do this sort of stuff easily in Python. For any non-trivial job it's better to have things like error handling, statistics, logs and *gasp* readability.

[-] DoYouNot@lemmy.world 13 points 8 months ago

Are you not using regex in Python to do that?

[-] teststodon@mastodon.social 1 points 8 months ago
this post was submitted on 01 Feb 2024
315 points (98.5% liked)

Comics

436 readers
1 users here now

A community for sharing comics related to programming

Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 8 months ago
MODERATORS