513
Expressions (lemmy.nz)
submitted 1 month ago by cannedtuna@lemmy.world to c/memes@lemmy.world
top 37 comments
sorted by: hot top new old
[-] CodingCarpenter@lemmy.ml 48 points 1 month ago

That third one is also sad

[-] very_well_lost@lemmy.world 26 points 1 month ago
[-] bhamlin@lemmy.world 7 points 1 month ago* (last edited 1 month ago)

Must be bad at regular expressions. I generally get far more than one extra problem when using them.

[-] Axolotl_cpp@feddit.it 4 points 1 month ago

No, you see, the RG was to solve the problems

[-] bhamlin@lemmy.world 1 points 1 month ago

Solve the problem of not having enough problems? 🤔

[-] 18107@aussie.zone 24 points 1 month ago

The past tense of regex is regrets.

[-] ignirtoq@feddit.online 24 points 1 month ago

*sees rfc822 in a regular expression*

I bet that's the email specification. That's probably an email address parser.

*checks*

Yep.

[-] Ephera@lemmy.ml 12 points 1 month ago

Perhaps worth adding that verifying an e-mail address via regex is difficult and not actually that useful.

Difficult, because a lot of e-mail addresses are syntactically valid. For example, a@b is valid. As is a@1.2.3.4. As is "spaces are cool 😎"@b (with the quotes).

And it's not that useful, because you need to send out an e-mail either way, if you want to know that it's the correct address and the user has access to it. A regex can't catch a typo in the actual words, for example.

If you want a basic sanity check to catch when the user types their name into the e-mail field, then you can require that it contains an @ and, if you want, that there's at least one symbol before and after.
If you go beyond that, you either need a massive regex or you're going to lock out users with unusual e-mail addresses.

[-] naticus@lemmy.world 5 points 1 month ago

Yep, these email address validation tools are the bane of my existence. I use a non-typical TLD and it sometimes gets flagged as invalid because it's not .com, .net, or .org.

[-] funkless_eck@sh.itjust.works 3 points 1 month ago

I've found many systems don't work with the .company TLD!

[-] kionay@lemmy.world 4 points 1 month ago

or some u.s.-centric ones that break with .co.uk

[-] virku@lemmy.world 2 points 1 month ago

I wrote one parser that checked the top level domain against a txt of all top level domains downloaded from Icann once a day. Was kind of proud of that one.

[-] naticus@lemmy.world 2 points 1 month ago

That's a pretty clever way of doing it!

[-] BiscuityCat@lemmy.world 13 points 1 month ago

I never understood why are people scared of regular expressions. I love them and they can be quite usefull.

Here is an example of one regex I wrote recently - it is used in replace:

(?:^-\[[^[]+\]$| ?\[.+?\] ?)
[-] Axolotl_cpp@feddit.it 6 points 1 month ago* (last edited 1 month ago)

Must be irony

[-] heartSagan5@lemmy.zip 1 points 1 month ago

I could use a use case. RegEx are pretty "what does it mean" without what it's targeted on.

[-] BiscuityCat@lemmy.world 1 points 1 month ago

I have mentioned it in the comments below, but to explain it simply, I just wanted to remove all the bracketed text + a dash if there is no other text.

[-] Funkt4st1c@lemmy.world 1 points 1 month ago

I started using regex because i need to rename a lot of my pirated media from "this_episode_uploaded_byXxXSuperEl33tSqwaaadXxX_MLP_s04_Episode7_bats.mkv"

and linux deals with it very nicely. Much better than manual, anyways

[-] lime@feddit.nu 1 points 1 month ago

that feels overcomplicated. you're always matching on square brackets anyway, so why make it a conditional? and one case not allowing spaces seems inconsistent...

[-] BiscuityCat@lemmy.world 1 points 1 month ago

It may feel like it, but I needed to handle all the edge cases. But if you think it can be simplified, I'm willing to learn.

[-] lime@feddit.nu 1 points 1 month ago* (last edited 1 month ago)

without knowing the format of the input data or what flags you're using it's obviously a bit harder to reason about, but since you're doing a replace i assume you don't care about the content of the bracketed text, you just want to remove it. the way i'm reading yours is

(?: # don't store this group
  # either
    ^  # start of line
    -\[[^[]+\]  # a -, a [ followed by at least one non-[, then a ] (passing one is fine)
    $  # end of line 
 | # or
  ?  # maybe one space
 \[.+?\]  # a [ followed by at least one character, then a ] (don't pass any)
  ? # maybe one space
)

since the two branches are almost identical, you can probably compact it into -?\s*\[.+?\]\s*. maybe a dash, then maybe some space, then angle brackets around something, then maybe more space.

[-] BiscuityCat@lemmy.world 4 points 1 month ago* (last edited 1 month ago)

You are right. It is just removal of the bracketed text. The input is multi-line string, so only flag used was the multi-line mode.

These are string lines I have encountered and how I wanted to change them:

1. "[...]"               -> ""
2. "-[...]"              -> ""
3. "-[...] text"         -> "-text"
4. "-text [...]"         -> "-text"
5. "[...] text [...]"    -> "text"
6. "-[...] text [...]"   -> "-text"

The main point is that I needed to remove the dash only if there is no other text on the line.

I have tried the regex you are suggesting at the beginning, but it failed at points (3) and (6).

EDIT: It just occurred to me that the first line of my comment sounds like stupid AI. 🤦

[-] lime@feddit.nu 1 points 1 month ago

aaah i see. then a conditional makes sense if you need to one-shot it. personally i would have run it through twice but i know there are systems that don't allow that.

[-] aMockTie@piefed.world 8 points 1 month ago

Why waste time doing any matching if wantarray == false? Just do:

if(!wantarray) { return 1; }

Before any matching happens, or if you only want one return statement set the value of a variable in if(!wantarray)/elsif(regex) and return that variable at the end.

[-] Funkt4st1c@lemmy.world 2 points 1 month ago

Im predicting AI. Alternatively random screenshot from Google, which is probably AI.

[-] OpenStars@discuss.online 8 points 1 month ago

Everyone loves perl though! /s

img

[-] SaharaMaleikuhm@feddit.org 8 points 1 month ago

What the hell kind of disgusting language is that? I need to know so I can avoid it at all costs.

[-] jaybone@lemmy.zip 13 points 1 month ago

Not sure if joking, but that looks like Perl.

I haven’t used it in like 20 years. There is a way to write it so that it’s not insane. You can write it kind of like C. But no one does that. So you end up looking at this crap.

It’s been referred to as a “write-only” language, as it’s not readable.

[-] raspberriesareyummy@lemmy.world 1 points 1 month ago

I know the reference from my perl days but I beg to differ. I wrote well-structured perl code with plenty of comments. I like to believe those projects of mine could be useful to someone else.

[-] cannedtuna@lemmy.world 10 points 1 month ago

The post is written in English 😔

[-] dukatos@lemmy.zip 3 points 1 month ago

fucking perl! Loved it...

[-] some_guy@lemmy.sdf.org 3 points 1 month ago

Perl being the first language I started learning, this makes me happy. Oh shit, press the button for the dog!

[-] raspberriesareyummy@lemmy.world 1 points 1 month ago

Oh boy... I like perl but as a first language, that musta been rough...

[-] CkrnkFrnchMn@lemmy.ca 2 points 1 month ago

Practice safe hex as they say...

[-] grandel@lemmy.ml 2 points 1 month ago* (last edited 1 month ago)

Panting can also be a sign of stress with dogs

[-] raspberriesareyummy@lemmy.world 2 points 1 month ago

Top notch shitpost. Extra credit for perl!

this post was submitted on 27 Sep 2026
513 points (98.1% liked)

memes

23157 readers
2521 users here now

Community rules

1. Be civilNo trolling, bigotry or other insulting / annoying behaviour

2. No politicsThis is non-politics community. For political memes please go to !politicalmemes@lemmy.world

3. No recent repostsCheck for reposts when posting a meme, you can only repost after 1 month

4. No botsNo bots without the express approval of the mods or the admins

5. No Spam/Ads/AI SlopNo advertisements or spam. This is an instance rule and the only way to live. We also consider AI slop to be spam in this community and is subject to removal.

A collection of some classic Lemmy memes for your enjoyment

Sister communities

founded 3 years ago
MODERATORS