Skip to main content

One post tagged with "regular expressions"

View All Tags

Multi-line Regex In Javascript with Comments

Phil Hadviger

Phil Hadviger

Principal Site Reliability Engineer @ GLG

Regular Expressions are great, but not easy to look at!

Let's take for example a regular expression in Javascript for parsing an email adddress.

^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$

To a trained eye this is likely as least readable enough, that they can guess that this parses an email address. But most people I work with, and myself included aren't going to be able to tell if there are any obvious bugs in this.