• Kempeth@feddit.de
    link
    fedilink
    English
    arrow-up
    2
    ·
    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.

    • Kempeth@feddit.de
      link
      fedilink
      arrow-up
      2
      ·
      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.

    • yoavlavi@programming.devOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      1 year ago

      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.

  • fubo@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    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.devOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          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
          link
          fedilink
          English
          arrow-up
          0
          ·
          1 year ago

          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!

          • Die4Ever@programming.dev
            link
            fedilink
            English
            arrow-up
            0
            ·
            edit-2
            1 year ago

            maybe it makes sense if you’re working on a project that uses a ton of different regexes and really depends on them, idk what kind of project that would be though

            maybe an html parser or web browser? /s

            seriously though this would be cool in a compiled language if it’s built in, but adding another build step to transpile your regexes might be a bit annoying especially if you’re using an interpreted language

  • jmacc93@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I used to hate regex, but after having had to use it a bunch and slowly getting used to the syntax, I can sort of read it quickly, and fully parse it if I stare at a regex expression long enough. It seems like having a DSL like regex is important because it does something well with a much shorter section of code than the equivalent host language code that does the same thing. But, it probably takes as long to understand a section of regex code as it does to understand the equivalent host language code, so it feels like you’re staring at a small block of impenetrable code, where you would otherwise be scanning a larger block of code. If that makes sense

    Props to the authors of this language

  • custom_situation@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    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 :veripawed3:@meow.social
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      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

      • custom_situation@lemm.ee
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

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

  • Pleonasm@programming.dev
    link
    fedilink
    English
    arrow-up
    0
    arrow-down
    2
    ·
    1 year ago

    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
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      1 year ago

      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.

      • SloppyPuppy@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        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.

      • custom_situation@lemm.ee
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        1 year ago

        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.

        • IronDonkey@lemmy.world
          link
          fedilink
          English
          arrow-up
          2
          ·
          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.

        • Kempeth@feddit.de
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          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
            link
            fedilink
            English
            arrow-up
            1
            ·
            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.

        • realitista@lemm.ee
          link
          fedilink
          English
          arrow-up
          1
          ·
          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.

      • NightAuthor@beehaw.org
        link
        fedilink
        English
        arrow-up
        0
        ·
        1 year ago

        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.

        • Kempeth@feddit.de
          link
          fedilink
          English
          arrow-up
          0
          arrow-down
          1
          ·
          1 year ago

          When you want to get better using a hammer, just treat everything as a nail.

    • Kempeth@feddit.de
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      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.

    • minorninth@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      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.