Skip to content

Instantly share code, notes, and snippets.

@proko
Last active December 2, 2015 19:06
Show Gist options
  • Select an option

  • Save proko/c389d88288bcab69ed63 to your computer and use it in GitHub Desktop.

Select an option

Save proko/c389d88288bcab69ed63 to your computer and use it in GitHub Desktop.
Expression examples and short explanations for Regualar Expressions

###Negative and Positive LookAhead

Negative lookahead is indispensable if you want to match something not followed by something else. When explaining character classes, this tutorial explained why you cannot use a negated character class to match a q not followed by a u. Negative lookahead provides the solution: q(?!u). The negative lookahead construct is the pair of parentheses, with the opening parenthesis followed by a question mark and an exclamation point. Inside the lookahead, we have the trivial regex u.

Positive lookahead works just the same. q(?=u) matches a q that is followed by a u, without making the u part of the match. The positive lookahead construct is a pair of parentheses, with the opening parenthesis followed by a question mark and an equals sign.

http://www.regular-expressions.info/lookaround.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment