this post was submitted on 27 Sep 2026
516 points (98.1% liked)
memes
23098 readers
2253 users here now
Community rules
1. Be civil
No trolling, bigotry or other insulting / annoying behaviour
2. No politics
This is non-politics community. For political memes please go to !politicalmemes@lemmy.world
3. No recent reposts
Check for reposts when posting a meme, you can only repost after 1 month
4. No bots
No bots without the express approval of the mods or the admins
5. No Spam/Ads/AI Slop
No 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
- !tenforward@lemmy.world : Star Trek memes, chat and shitposts
- !lemmyshitpost@lemmy.world : Lemmy Shitposts, anything and everything goes.
- !linuxmemes@lemmy.world : Linux themed memes
- !comicstrips@lemmy.world : for those who love comic stories.
founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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.
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
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.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:
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. 🤦
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.