HACKER Q&A
📣 giantg2

Best Regex Resources?


I'm looking for suggestions on books and sites for deeper understanding of regexes or a reference of the most useful ones.


  👤 solardev Accepted Answer ✓
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


👤 az09mugen
This site has good explanations of all kind of regexes [0]. I often use regex101 [1] to explain me difficult regexes.

[0] : https://www.rexegg.com [1] : https://regex101.com


👤 gregjor
Mastering Regular Expressions published a long time ago by O’Reilly. Still relevant, regexes haven’t changed much.