Skip to content

Instantly share code, notes, and snippets.

@a1exlism
Last active March 5, 2018 03:16
Show Gist options
  • Save a1exlism/7234f2ade88216553e00f8d69f1fb8ae to your computer and use it in GitHub Desktop.
Save a1exlism/7234f2ade88216553e00f8d69f1fb8ae to your computer and use it in GitHub Desktop.
let strA = 'JackChen is my friend.';
let strB = 'JackBlack is not my friend.';
// x(?=y) x is followed by y
let regX = /Jack(?=Chen)/g;
console.log(regX.test(strA)); // true
console.log(regX.test(strB)); // false
// x(?!y) x is NOT followed by y
let regY = /Jack(?!Chen)/g;
console.log(regY.test(strA)); // false
console.log(regY.test(strB)); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment