When we remap we go through the list of regexs looking for a match. What if we took all the regexes, removed subpattern captures, and created one giant pattern with alternation and capture of the regex for each rule, like:
(regex1)|(regex2)|...|(regexN) We could then just step through the array of subpattern capture offsets to find the matching rule. Then do a second match against just the original rule regex to get any captures it contains. Would this work, and would it be faster?