Skip to content

Instantly share code, notes, and snippets.

@AllThingsSmitty
Last active November 27, 2015 22:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllThingsSmitty/0aa2691aef9993132263 to your computer and use it in GitHub Desktop.
Save AllThingsSmitty/0aa2691aef9993132263 to your computer and use it in GitHub Desktop.
Testing regex in JavaScript with the exec() method
console.log(/p.*g/.test('programming')); // true
console.log(/p.*g/.test('pickles')); // false
var re = /quick\s(brown).+?(jumps)/ig;
var result = re.exec(
'The Quick Brown Fox Jumps Over The Lazy Dog'
);
console.log(result);
// ["Quick Brown Fox Jumps", "Brown", "Jumps"]
console.log(result.index); // 4
console.log(result.input);
// "The Quick Brown Fox Jumps Over The Lazy Dog"
// Credit: Louis Lazarus
@landed1
Copy link

landed1 commented Jul 26, 2015

Would be handy if this is a tutorial to show me the /p.*g/ which I think means contains p or g ?
But an interesting way to use gist...well done on that creativity. I hate regex can you tell and probably you the reader also does.

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