Skip to content

Instantly share code, notes, and snippets.

@NathanielWroblewski
Created November 3, 2014 20:32
Show Gist options
  • Save NathanielWroblewski/778680fb1ec3f8bf280d to your computer and use it in GitHub Desktop.
Save NathanielWroblewski/778680fb1ec3f8bf280d to your computer and use it in GitHub Desktop.
Positive and Negative Regex Lookahead and Lookbehind

Positive Lookahead

Match any "q" followed by a "u"

string.match(/q(?=u)/)

Negative Lookahead

Match any "q" not followed by a "u"

string.match(/q(?!u)/)

Positive Lookbehind

Match any "q" preceded by a "u"

string.match(/(?<=u)q/)

Negative Lookbehind

Match any "q" not preceded by a "u"

string.match(/(?<!u)q/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment