Re:What are your regex tricks?
by solardev on Tuesday June 25, 2024 @05:47AM
(#40786426)
I used to spend a lot of time writing these by hand with reference pages and such. But these days ChatGpt is so good at coming up with them (and/or debugging them) I just use that instead. It's basically just another language it can easily translate to and from.
Re:What are your regex tricks?
by jjice on Tuesday June 25, 2024 @11:10AM
(#40789613)
I really liked Mastering Regular Expressions by Jeffrey Friedl. He goes in depth on what they are (with a bit of FSA background) and how a regex engine works. It helps conceptualize what's going on and how to know what your specific regex library is doing.
Does that matter all that much? Not necessarily, but it's good to know things like whether or not your regex can blow in time complexity due to back tracking or not.
Other than that, there's a syntax overview that's very strong, and the rest is pretty straight forward from there - just applying sequential pieces one after the other to build your pattern.
I also like those regex crosswords - those are some of my favorite puzzles to do. I wish there were more of them! https://regexcrossword.com/
If something gets too complex, I tend to write a Tokenizer / Lexer these days. It's not that hard.
Does that matter all that much? Not necessarily, but it's good to know things like whether or not your regex can blow in time complexity due to back tracking or not.
Other than that, there's a syntax overview that's very strong, and the rest is pretty straight forward from there - just applying sequential pieces one after the other to build your pattern.
I also like those regex crosswords - those are some of my favorite puzzles to do. I wish there were more of them! https://regexcrossword.com/
You can enter something like this in ChatGPT: "Please give me 5 regular expressions that programmers find most useful."