Simplify backreference adjustment
This commit is contained in:
parent
3a1e9398ca
commit
6b660009ad
1 changed files with 2 additions and 5 deletions
|
|
@ -53,12 +53,9 @@ var Tokenizer = function(rules) {
|
|||
// Count number of matching groups. 2 extra groups from the full match
|
||||
// And the catch-all on the end (used to force a match);
|
||||
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.
|
||||
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);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue