• NegativeLookBehind@lemmy.world
    link
    fedilink
    English
    arrow-up
    70
    ·
    edit-2
    26 days ago

    I found your email address:

    (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
    
    • palordrolap@fedia.io
      link
      fedilink
      arrow-up
      8
      ·
      26 days ago

      That \\. part doesn’t look right, but what do I know. Apparently control codes are valid elsewhere, so a literal backslash followed by any character, even a space or a newline, might actually be valid there.

      “Yeah, my e-mail address is abc, carriage return, three backspaces and a terminal bell at example dot com. … What do you mean your mail program doesn’t support it?”

  • AngryClosetMonkey@feddit.nl
    link
    fedilink
    arrow-up
    20
    ·
    26 days ago

    Just pop them into regex101 or a similar tool, add sample data, see the mistake, fix the mistake, continue to do other stuff.

    • WhyJiffie@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      3
      ·
      24 days ago

      Just pop them into regex101 or a similar tool, add sample data, see the mistake, fix the mistake, continue to do other stuff. it works there, pull hair

      FTFY

  • Skyrmir@lemmy.world
    link
    fedilink
    English
    arrow-up
    14
    arrow-down
    3
    ·
    26 days ago

    Never debug regex, just generate a new one. It’s not worth the hassle to figure out not only what it does, but what it was meant to do.

    Better yet, just write it out in code, and never use regex. Tis a stupid thing that never should have been made.

    • potustheplant@feddit.nl
      link
      fedilink
      arrow-up
      15
      ·
      edit-2
      26 days ago

      Hard disagree. The function regex serves in programs like Notepad++ can’t be easily replaced by “writing it out in code”. With a very small number of characters you can get complex search patterns and capturing groups. It’s hard to read but incredibly useful.

      • chad@sh.itjust.works
        link
        fedilink
        arrow-up
        2
        arrow-down
        1
        ·
        26 days ago

        I fall in the abandon it camp. Code is read way more times than it is written. I’d rather read an algorithm that validates input than read a regex that validates input.

        • potustheplant@feddit.nl
          link
          fedilink
          arrow-up
          4
          ·
          26 days ago

          You’re discussing a completely different use case from what I said. RegEx can be increidbly useful but it’s not always the only/best option.

      • lightsblinken@lemmy.world
        link
        fedilink
        arrow-up
        1
        arrow-down
        2
        ·
        25 days ago

        feel like thats a notepad++ problem? in general, breaking it out into manageable human ingest-able chunks is A Good Idea

      • Skyrmir@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        arrow-down
        5
        ·
        26 days ago

        If you’re needing that level of complexity in a text file search, you already fucked up by putting the data in a text file. There’s a reason data file formats exist.

        • potustheplant@feddit.nl
          link
          fedilink
          arrow-up
          3
          ·
          26 days ago

          Not even close. Sometimes you can have a large text file where you need to do a find replace with a pattern. For example, in the translation world this can be a common occurrence for translation files (.xliff) or translation memories (.tmx).

          There’s a reason why this is widely used and it’s not because everyone else but you is dumb.

          • Skyrmir@lemmy.world
            link
            fedilink
            English
            arrow-up
            2
            arrow-down
            3
            ·
            26 days ago

            Turns out the million hours of coding put into SQL, makes it a better option than regex, even for xml based files.

            • potustheplant@feddit.nl
              link
              fedilink
              arrow-up
              3
              ·
              25 days ago

              Maybe for your very specific use case that’s true. However, other use cases exist and for many of those RegEx is the better option.

              • Skyrmir@lemmy.world
                link
                fedilink
                English
                arrow-up
                1
                arrow-down
                1
                ·
                25 days ago

                I’m saying if your use case makes regex the best option, you’ve gone the wrong way and should turn back. There are definitely corners you can paint yourself into that make it the way to go, but you’ve ended up there through a series of bad ideas.

                • potustheplant@feddit.nl
                  link
                  fedilink
                  arrow-up
                  3
                  ·
                  25 days ago

                  Maybe, just maybe, the context in which you use regex isn’t the same as everyone elses. But hey, who am I to deny you the disservice of thinking you’re the center of the world?

            • nickwitha_k (he/him)@lemmy.sdf.org
              link
              fedilink
              arrow-up
              1
              ·
              25 days ago

              Why would I use SQL to to reformat a poorly structured log file for programs whose source I have no input in during a live debug with a customer on system that I don’t own and can’t install anything on? Or to extract and format things like hosts from a similar file?

              That’s stuff that’s quickly and easily done in vim (which is generally part of the base install) with regex. There’s a lot of use cases that have no overlap with SQL.

              • Skyrmir@lemmy.world
                link
                fedilink
                English
                arrow-up
                1
                ·
                24 days ago

                So your use cases for regex are when you’re not going to actually fix the problem that caused you to need regex?

                • nickwitha_k (he/him)@lemmy.sdf.org
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  23 days ago

                  Modifying software that might not be within the scope of the company that I work for, much less my team, on systems that I explicitly do not have authorization to make such changes on? No, I would not be doing that.

                  An important thing to remember is that going all-in on a given tool is going to result in a bad time. You suggestion of SQL, for example, excels in querying and modifying data that lives in a database and follows the expected structures in said database. Most data is not in databases, nor is it structured in a compatible manner, if at all. The workarounds needed to coax SQL into performing such tasks would result in syntax both more arcane and more verbose than the regex necessary to transform it into something compatible.

                  Use the right tool for the right job. For transforming semi-structured and unstructured data into something useful in a practical amount of time, regex is frequently the right tool.

  • MTK@lemmy.world
    link
    fedilink
    arrow-up
    11
    ·
    25 days ago

    Downvoted so that everyone can know I’m cool since I understand regex better than the idiot who made that meme.

  • verstra@programming.dev
    link
    fedilink
    arrow-up
    6
    ·
    edit-2
    26 days ago

    If I have a complex regular expression to code into my app, I write it in pomsky, then copy paste the compiled regex to my source file, but also keep the pomsky source nearby. Much more maintainable.

  • over_clox@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    edit-2
    26 days ago

    This is basically code refactoring on a simplified level. You’re basically renaming a whole bunch of functions/tokens at once.

    Let’s say you’re renaming the variable ‘count’ under the method ‘buttplug’. First off, what do you rename it to?

    You start by replacing every instance of buttplug.count with a unique token, let’s say tnuoc.gulpttub.

    Then you replace that buttplug with a unique buttplug.

    Simple.

    • Trail@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      26 days ago

      Then you replace that buttplug with a unique buttplug.

      Rare buttplugs with good affixes are better than unique buttplugs.

  • kamen@lemmy.world
    link
    fedilink
    English
    arrow-up
    4
    ·
    26 days ago

    There are no bugs, it’s just not doing what you expect it to be doing…

    … which, now that I think of it, can be said about all software in general.