64x64 icon dark hosting
Deploy New Relic now and get $135 off your Tuts+ subscription.

How to use Lookaheads and Lookbehinds in your Regular Expressions


Today, we'll be reviewing the intricacies of regular expressions. More specifically, we'll discuss both how and why you should use positive/negative lookahead ands lookbehinds in your regular expressions. Originally meant to be a quick tip, this screencast ended up a bit longer than expected, at around eighteen minutes.

After viewing the video, keep in mind that, for any given task, there are a plethora of ways to match your desired text. For example, when matching a Twitter username – as we did in the video – you could also use a non-word-boundary, rather than a positive lookbehind.

The key is to find the right tool for the job.

Full Screencast