• Oneironaut21@ani.social
    link
    fedilink
    English
    arrow-up
    4
    ·
    4 months ago

    On average I’ve probably had to work with them or write one from scratch only a handful of times per year over my career. Not often enough to be an expert or anything but I’m not so afraid of them as I used to be.

  • spartanatreyu@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    4 months ago

    At least once every few days while coding, usually to do one of the following:

    1. Select multiple things in the same file at the same time without needing to click all over the place

      Normally I use multicursor keyboard shortcuts to select what I want and for the trickier scenarios there are also commands to go through selections one at a time so you can skip certain matches to end up with only what you want.

      But sometimes there are too many false matches that you don’t want to select by hand and that’s where regex comes in handy.

      For instance, finding:

      • parent but not apparent, transparent, parentheses, apparently, transparently
      • test but not latest, fastest, testing, greatest, shortest
      • trie but not entries, retries, countries, retrieve
      • http but not https

      … which can be easily done by searching for a word that doesn’t include a letter immediately before or immediately after: e.g. \Wtest\W.

    2. Search for things across all files that come back with too many results that aren’t relevant

      Basically using the same things above.

    3. Finding something I already know makes a pattern. Like finding all years: \d{4}, finding all versions: \d+\.\d+\.\d+, finding random things that a linter may have missed such as two empty lines touching each other: \n\s*\n\s*\n, etc…

  • FizzyOrange@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    4 months 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.

    • Dropkick3038@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      4 months ago

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

      • spartanatreyu@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        4 months 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)