I love writing regex, BUT when I have to change it, I much rather rewrite it from scratch. So I don't know if "elegant" is the exact label I'd put on it
It’s fine it also generated a five paragraph essay in comments about regex philosophy and why the requirements dictate that this implementation is the best.
I was about to say, unreadable regex is rendundant.
There's some things that aren't human readable, but are human parseable. A handful of characters that a human can decipher carefully over a few minutes while working through it. I typically talk myself though it (I guess that would be related to "duck debugging").
Regex, SQL queries, chained bitwise expressions, and not programming, but "dd" commands. I joke that the proper way to write a "dd" command is to write it out on paper, go home and sleep, come back the next day and see if you still agree with it, type it out in an email to a trusted colleague and get their review, then hold on to your lucky rabbits foot when you hit "enter" on the console.
Regexes are by far the simplest of the three. Unless by git you mean clicking randomly in a git GUI and by SQL you mean filtering your selects with Python.
Well, maybe it is easy when you understand. I have no problems typing my git commands and SQL is also not a problem, but reading or writing regex is always a hassle. regexr helps, but that is not really understanding it.
Just use one of the many cheatsheets and work through it. Also regex101.com is helpful. Im really not a master at this and rarely need it, but with a little tinkering i was always able to get a working regex doing what i wanted.
I use it so rarely that it seemed never enough to need to learn it properly.
What do you mean by rarely? I use it nearly every day. Don’t you ever need to search, or search and replace things? And sometimes validate some things?
Do you have a good learning resource?
Most programming language offering them have a perfectly good documentation about their regex engine. Take the time to read it, tests the things you learn, and you should be fine.
idk if my reading is correct but if it's correct this seems quite readable, probably wrong guess though
match
192.168.8.1
1+ whitespaces
0x
1+ non whitespaces (idk if it intended to be [^\s]+ instead of [^\s+])
1+ whitespaces
0x
1+ non whitespaxes
1+ whitespaces
capture group 'mac' start
1+ case-agnostic hex character
capture group 'mac' end
25
u/santiagobustelo Sep 21 '26
I seem to be one of the few persons that find regex elegant and even enjoyable.
14
u/theFirstHaruspex Sep 21 '26
Tell me more about this implied mystical "readable regex"
4
u/alexstankovic Sep 21 '26
What do you mean unreadable regex, there is a readable version?
6
u/JAXxXTheRipper Sep 21 '26
All regex is unreadable.
2
u/fpcoffee Sep 21 '26
uhoh.. that’s possible? 😳😳😳
2
u/MrFrog2222 Sep 21 '26
There is no such thing as readable regex
2
u/navetzz Sep 21 '26
So unreadable code...
2
u/FurieMan Sep 21 '26
I can read my own regex. It takes about as long to read as it took to write. But I can read it.
2
u/enigma_0Z Sep 22 '26
It’s fine it also generated a five paragraph essay in comments about regex philosophy and why the requirements dictate that this implementation is the best.
2
u/GargantuanCake Sep 22 '26
No regex is readable.
1
u/thorwing Sep 21 '26
Regex might look complicated but its a very quick and easy way to share constraints over multiple environments.
Frontend -> Backend -> Database
1
u/BolunZ6 Sep 21 '26
Since when regex is readable
1
u/yumii- Sep 21 '26
I have to Google regex guides everytime I need to write it so I can't really blame the AI on this one
1
u/brainfreeze91 Sep 21 '26
When the AI generates readable, maintainable code, you should buy a lottery ticket
1
u/DiscombobulatedSun54 Sep 21 '26
There are readable regexes? 😱
1
u/_redisnotblue Sep 22 '26
There's no such thing as a readable regex
1
u/Z3t4 Sep 22 '26
Something something skill issue, something job security.
1
u/code_monkey_001 Sep 27 '26
No such thing as an unreadable regex, just a less-than-literate reader. If a computer can parse it, it is by definition readable.
1
u/oldflatterhand Oct 11 '26
It's ugly and unreadable per default.. but also one of the most elegant ways to solve things
-2
u/-Debugging-Duck- Sep 21 '26
WTH do you all do with AI that you get shitty code? Do you know how to prompt? lol
299
u/[deleted] Sep 21 '26
[removed] — view removed comment
0
u/[deleted] Sep 21 '26
[deleted] — view deleted comment