Simplify backreference adjustment
This commit is contained in:
parent
3a1e9398ca
commit
6b660009ad
1 changed files with 2 additions and 5 deletions
|
|
@ -54,11 +54,8 @@ var Tokenizer = function(rules) {
|
||||||
// And the catch-all on the end (used to force a match);
|
// And the catch-all on the end (used to force a match);
|
||||||
var matchcount = new RegExp("(?:(" + state[i].regex + ")|(.))").exec("a").length - 2;
|
var matchcount = new RegExp("(?:(" + state[i].regex + ")|(.))").exec("a").length - 2;
|
||||||
|
|
||||||
// Get how long references can be, depending on how many capturing groups have been found so far.
|
|
||||||
var reflength = ("" + (matchTotal + matchcount.length - 2)).length;
|
|
||||||
|
|
||||||
// Replace any backreferences and offset appropriately.
|
// Replace any backreferences and offset appropriately.
|
||||||
var adjustedregex = state[i].regex.replace(new RegExp("\\\\([0-9]{1," + reflength + "})", "g"), function (match, digit) {
|
var adjustedregex = state[i].regex.replace(/\\([0-9]+)/g, function (match, digit) {
|
||||||
return "\\" + (parseInt(digit, 10) + matchTotal + 1);
|
return "\\" + (parseInt(digit, 10) + matchTotal + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue