Lea Verou on Regular Expressions

Ilya Gelman

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\.)?([^\ ]*)$/

On Thursdays we post videos that we believe are worth watching and that can make you a better front-end developer. Have such a video to share? Share with us

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

Popular