• @[email protected]
    link
    fedilink
    41 year ago

    Yesterday doing a search using vim for a class that shared a lot of characters at the front with many other classes: /Bas.*Some I could have done a more precise search with better regex, but this was quick, easy, and worked.

  • @[email protected]
    link
    fedilink
    51 year ago

    Interesting to see a lot of these responses (so far) are workflow related instead of being used in production.

    • lad
      link
      fedilink
      English
      21 year ago

      Probably, because in production there are really few things that are best done with regex. Most use I had for regex in production is filling in data from user-provided files with specifically crafted names, and even there there was some guesswork because of errors in naming, and the same thing may have been achieved without regex by splitting and/or iterating

    • @[email protected]
      link
      fedilink
      11 year ago

      Usually I use glob patterns for test selection.

      But I did use reges yesterday to find something else. A java security file definition.

  • @[email protected]
    link
    fedilink
    English
    2
    edit-2
    1 year ago

    Earlier this week for a character range.

    /edit: Now I remember. For setting up a new entry in Jenkins CI build failure analysis - identifying the build failure cause in the log.

  • @[email protected]
    link
    fedilink
    21 year ago

    We use it for triaging test failure (running tens of thousands of tests for CPU design verification).

    That use is acceptable because it is purely informational. In general you should avoid regexes at all costs. They’re difficult to read, and easy to get wrong. Generally they are a very big red flag.

    Unfortunately they tend to get used where they shouldn’t due to lazy developers not parsing things properly.

    • @[email protected]
      link
      fedilink
      1
      edit-2
      1 year ago

      regexes are a well established solution for parsing strings. what exactly is the “proper” alternative you propose?

      • @[email protected]
        link
        fedilink
        11 year ago

        There are some tools/libraries that act as a front-layer over regex.

        They basically follow the same logic as ORMs for databases:

        1. Get rid of the bottom layer to make some hidden footguns harder to trigger
        2. Make the used layer closer to the way the surrounding language is used.

        But there’s no common standard, and it’s always language specific.

        Personally I think using linters is the best option since it will highlight the footguns and recommend simpler regexes. (e.g. Swapping [0-9] for \d)

  • NostraDavid
    link
    fedilink
    61 year ago

    Yesterday, when I had a file with a list of JSON objects, and I wanted to move the date field at the end to the beginning, so I used regex find and replace to move it. Something like \{(.*?), ("date": ".*?") in Search, and then {$2, $1 in replace (or something close to it).

    Yes, I refactor code and data using regex. I can’t be arsed to learn AWK (even though I should).

    • whoareuOP
      link
      fedilink
      31 year ago

      AWK doesn’t work with json IIRC. You have to use jq to deal with json.

      • NostraDavid
        link
        fedilink
        11 year ago

        While yes, the way I had it structured looked like a CSV if you squinted a little, I do fully agree AWK can’t be used for just any old JSON.

        jq is dope, but that language still feels pretty confusing IMO.

    • whoareuOP
      link
      fedilink
      31 year ago

      https?//[a-zA-Z0-9_-]*

      I am kinda learning RE right now 😅

        • whoareuOP
          link
          fedilink
          21 year ago

          If we want to include every protocol then the RE could be complex.

          • lad
            link
            fedilink
            English
            11 year ago

            Depending on the use-case it maybe should. On the other hand, some things are better left to library implementations rather than custom regex, e.g. email validation