Lea Verou on Regular Expressions
Ilya Gelman
Last updated on Sep 28, 2017

Regular expressions are a very powerful thing and a lot of junior developers struggle to wrap their heads around it and remember the syntax.

In her talk from Fluent Conference 2012, Lea Verou explains Regular Expressions in JavaScript in a very interactive and interesting way.

There is a library called Verbal Expressions that allows you to describe regular expressions in an expressive way (no pun intended). There are implementations in various languages, in JavaScript it looks something like this:

VerEx()
  .startOfLine()
  .then('http')
  .maybe('s')
  .then('://')
  .maybe('www.')
  .anythingBut(' ')
  .endOfLine();

The above code will compile into this RegExp:

/^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/

P.S. Remember, never try to parse html with regular expressions!

Back to all articles

© 500Tech. Building high-quality software since 2012.