I'm parsing a moderately complex grammar using Javascript and I'd like to use regular expressions to match tokens such as numbers.
Given a string containing the grammar, a regular expression representing a number (say) and an offset within the string, I'd like to find out if the regular expression matches the string at that offset exactly.
I can set lastIndex, call RegExp.exec and check the index property of the resulting match to see if the match happened at the expected offset, but this is very inefficient because exec will search the entire string if it doesn't find a match at the starting offset.
The Javascript spec says "A Pattern evaluates ("compiles") to an internal procedure value. RegExp.prototype.exec can then apply this procedure to a String and an offset within the String to determine whether the pattern would match starting at exactly that offset within the String."
This is exactly what I want, but there seems to be no way of accessing this internal function. Does anyone know if there is?
P.S. I'm currently avoiding this problem by splitting the input string into an array of tokens, but I'd prefer not to.