27
jkuhl
5y

Regex.

I HATE YOU.

There. I've said it.

I spent the better part of the last hour trying to wrangle together, not one, but TWO regexes and getting them to work with Python's "re" module.

The worst part about these little shits? It's how well they work once you figure out how to get them to work. For example, pulling a phone number out of a paragraph is difficult with string methods, but cake with regex . . . if you can figure out the pattern.

But I think I'll always have hate in my heart for Regex just for how obtuse and frustrating they can be.

F**k you regex.

Comments
  • 18
    “Some people, when confronted with a problem, think ‘I know, I'll use regular expressions.’ Now they have two problems.”

    —Jamie Zawinski

    Obligatory quote. But seriously, this is a classic use case for regex. Did you by chance find https://python.developpez.com/cours... in your searches?
  • 8
  • 10
    Obligatory www.regex101.com link
  • 3
    @irene Nailed it.
  • 4
    I hated Regex too when I was new to it, but now I actually like it.

    It is especially useful for search and replace stuff if I want to replace some code but always keep some matching group in the middle.
  • 1
    Also unless you have a very niche application for regex, just Google what your use case is with regex and someone most likely already made a viable one! No need to reinvent the wheel.
  • 1
    Regex are not that bad when you find enough peace of mind to face them
  • 2
    Protip : to future-proof your regex, break it into blocks with a comment for their meaning, and then concatenate them (at compile time if you can).

    Do I use this super handy technique on some of my own, 80+ chars long regex? HELL NO

    ALL HAIL REGEX101
  • 4
    Use regexr.com
  • 2
  • 1
  • 1
    @lazyDev too bad it's a dead account
  • 2
    @Matt-Smeets yeah too bad. But Who the hell creates an account to just ++ a Rant and vanish !
  • 3
    Problem with regex is that every implementation uses its own dialect. So switching between Perl, Python, Lua and Bash I always need the manual
  • 1
    https://regexr.com

    I always use this if I get real stuck. Just keep trying to you get what you needed.
  • 2
    Regex is a black art, practiced by witches and warlocks
  • 1
    @martygeek they practice the dark art of วฅษษ‡แตฝ... ๐–Œ๐–—๐–Š๐–•... ๐•˜๐•ฃ๐•–๐•ก... ๐š๐š›๐šŽ๐š™... gๅฐบไน‡๏ฝฑ... ๏ปฎะณั”ืง... γρεπ... โ“–โ“กโ“”โ“Ÿ....

    Ironically, you’ll have a hell of a time matching the word “grep” in the above paragraph using a regular expression :D
  • 0
    @martygeek ๐Ÿค” Can't argue with that
  • 0
    @irene you got me there.... :)
Add Comment