News for hackers. Stuff that matters.
Re:What are your regex tricks? by cpach on Tuesday June 25, 2024 @03:45AM (#40785630)
Perhaps I’m boring, but I generally prefer to keep them as simple as possible (^_^)
Re:What are your regex tricks? by sandreas on Tuesday June 25, 2024 @04:54AM (#40786091)
A cheatsheet, stackoverflow and https://regex101.com/ - and of course a basic understanding of regular expressions in general.

If something gets too complex, I tend to write a Tokenizer / Lexer these days. It's not that hard.

Re:What are your regex tricks? by cpach on Thursday June 27, 2024 @10:27AM (#40810895)
Out of curiosity, do you perhaps have some specific examples where you opted to write a tokenizer/lexer?
Re:What are your regex tricks? by sandreas on Thursday June 27, 2024 @12:13PM (#40812105)
[delayed]
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/

Re:What are your regex tricks? by Naira_Nicol on Thursday June 27, 2024 @08:18AM (#40809677)
What is that?
Re:What are your regex tricks? by cpach on Thursday June 27, 2024 @10:05AM (#40810697)
Re:What are your regex tricks? by gtirloni on Thursday June 27, 2024 @08:44AM (#40809873)
OP is probably asking about useful regular expressions that people might have.

You can enter something like this in ChatGPT: "Please give me 5 regular expressions that programmers find most useful."