this post was submitted on 16 Jul 2023
260 points (93.3% liked)

Programming

17450 readers
156 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
top 50 comments
sorted by: hot top controversial new old
[–] Pleonasm@programming.dev 29 points 1 year ago (5 children)

Who is this for? People who write lots of regular expressions won't need it because they know what they're doing and people who don't write lots of regular expressions probably won't find it anyway.

It just seems like a weird type of user who actually wants this.

[–] realitista@lemm.ee 28 points 1 year ago* (last edited 1 year ago) (3 children)

I almost never use regex, but when I do, I'd love something like this. Exactly because I don't use regex enough to be bothered learning it's impenetrable syntax.

[–] NightAuthor@beehaw.org 7 points 1 year ago (2 children)

I learned enough to see how powerful it was, then started using it within Sublime Text to edit data from time to time. (Extract URLs or something from a websites code, reformat X or Y data for a script I’m hacking together) and I’ve slowly retained more and more of the elements I repeatedly use. I think I’ve actually got a pretty good grasp on it. Maybe you should be using it more.

[–] realitista@lemm.ee 5 points 1 year ago

I'm not a programmer by trade so I only program when I need something and regex is a small subset of that. Usually I find something someone else wrote and adapt it to my needs. But it would be nice to be able to write things from scratch, this would be a helpful tool for that for sure.

load more comments (1 replies)
[–] custom_situation@lemm.ee 6 points 1 year ago* (last edited 1 year ago) (3 children)

i mean, you can learn the basics of matching in 30 minutes or less. that core knowledge will be broadly applicable across any tool that uses regex. things get much easier once to have a handle on the basics.

…or you can learn this regex dsl and still have to learn regex. the difference is you’re learning a non-portable regex syntax.

[–] Kempeth@feddit.de 6 points 1 year ago (2 children)

Sure. I just very rarely need just basic regexes.

And once you go beyond these the syntax gets very obtuse. Which means I'm spending an hour+ googling something close to what I need and then using a sandbox to try and tweak it until it does what I need. Then I paste something into my code that I won't understand anymore 5 minutes into the future - which isn't exactly great for maintainability.

[–] realitista@lemm.ee 3 points 1 year ago

This is a good point too. Just because you don't use regex often doesn't mean your needs are simple. They are probably much the same as someone who uses it often. Which is why readability and less learning curve is a good thing.

[–] IronDonkey@lemmy.world 5 points 1 year ago

You're right, I can learn the basics of regex in 30 minutes. Then I can write my one regex. Then I can forget the basics of regex in 3 minutes, because regex's syntax is random garbage that makes no intuitive sense, and I hate and suck at memorizing nonsense. Repeat every 4-16 months.

It's true though that regex is entrenched enough that even if something is easier to read, it's unlikely that it'll replace regex any time soon. You'd need a couple big names to adopt it, then many years.

But if there's a readable replacement that can convert to and from regex - well, screw it, I'm in. Even if I'm required to use regex in some program, if I can write something that makes sense without the requisite half hour of googling crap, I'll just use it as a separate tool to make and read regex strings.

[–] realitista@lemm.ee 2 points 1 year ago

Probably I've spent the 30 minutes 5-10 times over my life. But then it's a few years till I need it again and I need to spend the 30 minutes again.

[–] SloppyPuppy@lemmy.world 1 points 1 year ago (1 children)

I just learned to type what I want from a regex in chatgpt and call it a day. It works pretty well.

Also fuck regex.

load more comments (1 replies)
[–] curiousaur@lemmy.fmhy.ml 11 points 1 year ago (1 children)

I think it's for me. I occasionally need regular expressions, like any career programmer. I also hate regular expressions. I have to complely relearn the every time I use them.

I'm not a programmer, but I do have to write scripts, and I'm the same way with regex.

[–] minorninth@lemmy.world 5 points 1 year ago (1 children)

OK, let's say you've got a bunch of regexes in a source repository that need to get modified frequently. It can be difficult to code-review complex regexes, and even harder to code-review changes to an existing regex.

Something like this might actually help. A change to a complex regex might actually produce a more clear diff of a subset of lines.

Also, I think being able to comment in the middle of a regex would be super handy for that type of code.

load more comments (1 replies)
[–] Kempeth@feddit.de 5 points 1 year ago (1 children)

me for example. I don't write regex often enough to be really familar with the cryptic syntax. But I do use them every once in a while and dread the occasion every time. Having a more expressive way to write pattern matching instructions would be really useful to me.

[–] Pleonasm@programming.dev 4 points 1 year ago (2 children)

But then you'll have to learn the syntax of this instead.

I suspect that if you actually start using Melody you won't find it as helpful as you think you might. Maybe I'm wrong. Let's see in a year's time.

load more comments (2 replies)
[–] Spzi@lemm.ee 2 points 1 year ago

It might be used in education. Some who learned it this way might stick to it, or advance to your first group.

[–] janWilejan@kbin.social 20 points 1 year ago (2 children)

Oh great. A new flavour of regex, but it's less portable and more verbose. https://xkcd.com/927/

[–] yoavlavi@programming.dev 9 points 1 year ago* (last edited 1 year ago) (3 children)

I wouldn't consider Melody a new flavour of regex as it compiles to ECMAScript regular expressions.

I'd consider being more verbose than regular expressions as a great thing for what this project aims to do, regular expressions are very write optimized which is the wrong (IMO) tradeoff to make in a shared codebase (or even your personal code that's more than a few days old) where code is read much more often.

[–] custom_situation@lemm.ee 4 points 1 year ago

respectfully disagree—this is very much a regex dsl. folks still need to conceptually understand regex to use this, which begs the question about who this is for.

the best use case i can think of is large and complicated expressions, but i’d need to see more of that to have a definitive opinion.

[–] NightAuthor@beehaw.org 3 points 1 year ago

I don’t know all the forms of regex but might it be useful to have this capable of compiling to different types of regex?

[–] vrighter@discuss.tchncs.de 2 points 1 year ago

if it can only be used to create regexes, and all programs compile to regexes, then it is a regex flavor in itself.

And let's not kid ourselves, regexes are not that hard. They can look cryptic, but in most cases they're not really that hard to understand.

all this does is make it much more verbose and introduce the HUGE inconvenience of a separate compiler for regexes, since regexes are typically embedded within other files written in other languages that this compiler can't understand. So somehow regexes would end up needing their own file.

[–] Kempeth@feddit.de 5 points 1 year ago

but it’s less portable and more verbose

you misspelled "less obtuse and more expressive"

Also it doesn't compete with regex. It's an abstraction layer. You know, the thing programmers have been building since the dawn of programming to make everyone's lives easier. There's a reason why everyone who has the option to has stopped working directly with assembly and C.

[–] fubo@lemmy.world 17 points 1 year ago (1 children)

Sure, but can it go the other way — turn a regexp string into a parse tree and then into Melody syntax?

Or, at least, the equivalent of CL-PPCRE's parse-string?

[–] yoavlavi@programming.dev 20 points 1 year ago (1 children)

That's not supported yet but is planned (see the "reverse compiler" feature in the README)

[–] Die4Ever@programming.dev 17 points 1 year ago (2 children)

sounds like it would make an amazing VSCode extension

[–] yoavlavi@programming.dev 8 points 1 year ago

Awesome idea, will definitely take it into consideration when that feature is available. Melody actually has a VSCode extension with highlighting and snippets, could be added to that

[–] Grandwolf319@sh.itjust.works 2 points 1 year ago (2 children)

Yeah, I think it makes little sense to have another programming language to create a regex but it sounds like a great regex inspect tool.

Keep everything in regex, want to change something complicated? You can translate it into this language, tweak it, then translate it back!

load more comments (2 replies)
[–] Pika@lemmy.world 15 points 1 year ago

Nothing makes sense about this, how can anyone understand this. I think I will stick with standard RegExp. It's short, it's simple yet complex at the same time. And it gets the job done

[–] vrighter@discuss.tchncs.de 13 points 1 year ago

oh god no, that's an even bigger abomination than regex themselves

[–] Kempeth@feddit.de 10 points 1 year ago

I am very much in the market for a way to do regex without resorting to incantations that look like someone spilled a bag of special characters. Just not on JS...

You seem to be the author. A suggestion to you. You should really rethink your playground. All it currently does is turning melody into regex, which is important to have for comparison. But you're specifically courting people who DON'T want to deal with regex syntax. What you desperately need is a way to run melody expressions. And - if possible - a way to translate regex into melody wouldn't hurt as well.

Many (most?) of us tend to google regex on the web and pasting them in our code. Having them converted into a syntax that we can better understand would be hugely helpful.

[–] BestBunsInTown_@lemmy.world 7 points 1 year ago

This look greats! Hopefully I can start skipping chatGPT for regex

[–] randombit@lemmy.sdf.org 6 points 1 year ago (1 children)

I can’t say this is for me. What I really need is something that will convert one flavor of regex to another. It’s really annoying to always have to look up the shortcuts and capture group syntax.

[–] ajjlyman@lemmy.sdf.org 2 points 1 year ago

Yes! I actually had this exact desire years ago, and went searching for it. RegexBuddy does this, best $US 40 I've spent. It'll even do its best to make something that'll match the same things, even if you're using features that aren't technically supported in the target. Don't worry, it'll describe exactly what doesn't work, and why, when it does that.

For example, if I ask it to convert from C# /(?>atomic) case-(?i)insensitive(?-i) string/ to JavaScript (chrome) it'll throw out: /(?:atomic) case-[iI][nN][sS][eE][nN][sS][iI][tT][iI][vV][eE] string/, along with the warning:

Conversion is incorrect because the target application's regular expression flavor doesn't have certain features: JavaScript (Chrome) does not support atomic grouping

[–] xtremeownage@lemmyonline.com 6 points 1 year ago

eh, If your goal is to make regular expression simpler, a web application where users can click to generate things would prob be easier.

[–] maegul@lemmy.ml 5 points 1 year ago

Quickly looking at the readme, it seems nice and readable. I’d be curious though to see examples of monster expressions, as I’d be worried that Melody’s syntax wouldn’t be so helpful there (not sure though).

I don’t mind the verbosity, but it does feel like it leans a tad too much plain language with the some of … stuff.

It’d be cool if it could also produce train track diagrams.

[–] Bishma@social.fossware.space 4 points 1 year ago

But I learned Perl in the 00's and I don't want those neurons to go to waste!

[–] superfes@lemmy.world 4 points 1 year ago

Think I'll just stick to regular expressions...

[–] custom_situation@lemm.ee 4 points 1 year ago (2 children)

so, where’s the email address regex? that’s where this lives or dies. there is no reason to use this for extremely simple happy-path regexes.

i’m having a tough time understanding who this is for. a beginner might think this is great, but they’re shooting themselves in the foot by adding an additional layer of abstraction rather than reading something to learn the basics.

[–] TerrorBite@meow.social 6 points 1 year ago (3 children)

I am of the opinion that regex for email address is a bad idea. The only two things that you need to check an email address are:

Does the address contain an @ symbol?
Is there a dot to the right of the @ symbol?

Then just try to deliver to it, and let the MTA do the rest.

Email addresses can be complicated, and there's plenty of valid addresses that can be excluded by attempts at regex validation.

@custom_situation @yoavlavi

[–] Zikeji@programming.dev 3 points 1 year ago (1 children)

I agree. In fact, the only check is if it contains the @ symbol, since "com" and other TLDs/gTLDs can have MX records, it is possible to have email@com. Not that we'd ever see it in practice though.

[–] TerrorBite@meow.social 2 points 1 year ago

@Zikeji It's possible for TLDs to have A records, and for a while there were a few that did. But ICANN forbids top level A records, and I wouldn't be surprised if they forbid top level MX records as well.

Anyway, you would literally enter the address as "email@com." including the trailing dot, which represents the DNS root that contains all the TLDs. You can also think of the trailing dot as an indicator of a FQDN (instead of a hostname within your local search domain).

[–] custom_situation@lemm.ee 2 points 1 year ago

i said “email” but what i meant was “show me a complicated example”. i don’t disagree with anything you said.

[–] dhruv@lemmy.dbzer0.com 1 points 1 year ago

If it can do that, i might just use it. It'll make code a whole lot cleaner to read.

load more comments (1 replies)
[–] Reptorian@programming.dev 3 points 1 year ago

Hmm, I think I will give it a star in case I need something like this. I did use regex enough to know how it works though I do have a offline regex101 software to aid into that.

[–] kronicmage@lemmy.ca 3 points 1 year ago

Just use parser combinators

[–] tinwhiskers@kbin.social 3 points 1 year ago (1 children)

Oh nice. An entire language that is write-only.

[–] custom_situation@lemm.ee 2 points 1 year ago

this is really the problem here. it’s very much lipstick-on-a-pig and doesn’t actually reduce complexity.

[–] verstra@programming.dev 2 points 1 year ago

I prefer the pomsky syntax. https://pomsky-lang.org/

load more comments
view more: next ›