Last active
November 27, 2015 22:55
-
-
Save AllThingsSmitty/0aa2691aef9993132263 to your computer and use it in GitHub Desktop.
Testing regex in JavaScript with the exec() method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.