Javascript Regex Exec

javascript-regex

regexObj.exec(str)

The exec() method executes a search for a match in a specified string. Returns 
a result array, or null.  If you are executing a match simply to find true or 
false, use the RegExp.prototype.test() method or the String.prototype.search() 
method.
If the match succeeds, the exec() method returns an array and updates properties 
of the regular expression object. The returned array has the matched text as the 
first item, and then one item for each capturing parenthesis that matched 
containing the text that was captured.  If the match fails, the exec() method 
returns null.

// Match "quick brown" followed by "jumps", ignoring characters in between
// Remember "brown" and "jumps"
// Ignore case
var re = /quick\s(brown).+?(jumps)/ig;
var result = re.exec('The Quick Brown Fox Jumps Over The Lazy Dog');
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License