Methods: include() & exclude()
By default, the result.rules object retains the sub-phrases matched by all named rules. Often there are rule names that are of no interest. The include() and exclude() methods can be used to limit the list of rule names retained in the results.
Syntax
var exp = new apgExp(pattern[, flags]); exp.include(array); exp.exclude(array);
Parameters
• array: An array of rule names (strings) to include/exclude.
Return
none
Example 1
By default, all matches to all rules are retained in the result.rules object.
var pattern, str, exp, result; pattern = 'word = alpha *(alpha / num)\n'; pattern += 'alpha = %d65-90 / %d97-122\n'; pattern += 'num = %d48-57\n'; str = "ab12"; exp = new apgExp(pattern); result = exp.exec(str); console.log(result.toText()); /* returns */ result: [0]: ab12 input: ab12 index: 0 length: 4 tree depth: 7 node hits: 26 rules: word : 0: ab12 : alpha : 0: a : alpha : 1: b : num : 2: 1 : num : 3: 2
Example 2
By using exclude(["alpha", "num"]) "alpha" and "num" are removed from the result.rules object.
/* same as Example 1 except */ exp = new apgExp(pattern); exp.exclude(["alpha", "num"]) result = exp.exec(str); console.log(result.toText()); /* returns */ result: [0]: ab12 input: ab12 index: 0 length: 4 tree depth: 7 node hits: 26 rules: word : 0: ab12
Example 3
By using include(["word"]) all rules except "word" are removed from the result.rules object.
/* same as Example 1 except */ exp = new apgExp(pattern); exp.include(["word"]) result = exp.exec(str); console.log(result.toText()); /* returns */ result: [0]: ab12 input: ab12 index: 0 length: 4 tree depth: 7 node hits: 26 rules: word : 0: ab12