DEV Community

Discussion on: How do you feel about regex?

Collapse
 
fjones profile image
FJones

Regex is one of our most useful tools, when used appropriately. But that requires good knowledge of regex (such that you actually understand what you're doing) and good knowledge of the limitations.

If you're touching HTML with regex, chances are you're doing it wrong.
If you need backreferences and readaheads, chances are you're doing it wrong.
If you're only using .*, chances are you're doing it wrong.

I recommend that anyone who wants to understand regex implement a small regex parser for themselves, to get a greater understanding of how it works. Alternatively: Try to rewrite your regex pattern exclusively in terms of |+.() to explain what it actually does. Everything else in the basic regex syntax builds off of that.