Ask HN: Best Regex Resources?

3 points by giantg2 ↗ HN
I'm looking for suggestions on books and sites for deeper understanding of regexes or a reference of the most useful ones.

3 comments

[ 2.0 ms ] story [ 19.0 ms ] thread
Mastering Regular Expressions published a long time ago by O’Reilly. Still relevant, regexes haven’t changed much.
Not a direct learning resource, but a few quick tips:

1) Know what language you're targeting beforehand, if possible (e.g. Javascript regex or Perl regex or POSIX regex, etc.). There are a lot of different regex "dialects" (kinda like SQL dialects) and the operators aren't always compatible, and not every implementation supports all the features (like "negative lookaheads").

2) Railroad diagrams can be really helpful, e.g. https://regexper.com/#%5E%28%5BA-Z%5D%7B3%7D%29-%28%5Cd%7B4%...

3) ChatGPT is actually really good at both generating and explaining regex statements. You should always verify its output against some tests, but it can usually get you 95% of the way there with minimal effort. I learned regex the hard way back in the Perl days, but just use ChatGPT to make all of them now