Method: exec()
The exec() method executes a search for a match in a specified string.
Syntax
var exp = new apgExp(pattern[, flags]); var result = exp.exec(str);
Parameters
- str: string/array: The string to search for a pattern match in. May be a string or array of integer character codes.
Return
If the match succeeds, a result object is returned, otherwise null.
Example
var pattern, str, exp, result;
var printResult = function(result){
if(result){
console.log("found: " + result[0] + " :at: " + result.index);
}else{
console.log("not found: result: " + result);
}
}
pattern = 'pattern = "abc"\n';
exp = new apgExp(pattern);
result = exp.exec("---abc");
printResult(result);
result = exp.exec([45, 45, 45, 97, 98, 99]);
printResult(result);
result = exp.exec("xyz");
printResult(result);
/* returns */
found: abc :at: 3
found: abc :at: 3
not found: result: null