Skip to content

Instantly share code, notes, and snippets.

@martinhj
Created April 4, 2019 13:11
Show Gist options
  • Save martinhj/502334e63c1e891565fa8627d3b29538 to your computer and use it in GitHub Desktop.
Save martinhj/502334e63c1e891565fa8627d3b29538 to your computer and use it in GitHub Desktop.
Javascript lookahead & -behind
// positive lookahead
// ?=
const lookaheadRegex = /something(?=\$)/ // match something at end of line, but not the end of line
// positive lookbehind
// ?<=
const lookaheadRegex = /(?<=\^)something/ // match something at the start of line, but not the start of line
// negative lookahead
// ?!
const lookaheadRegex = /something(?!\$)/ // match something not at the end of line
// negative lookbehind
// ?<!
const lookaheadRegex = /(?<!\^)something/ // match something not at the start of line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment