Brent Dax asked: > Will that handle captures correctly?
I believe so. Each (successful) time through the loop we cache a reference to the candidate's match object, which will successfully have stored all the captures from the candidate's matching. Then we reinstate the best candidate, by binding it to $0. Hence the best candidate (with its stored captures) becomes the "official" match of the rule. > Maybe you should temporize $0... $0 is lexical to each regex/rule. No need to temporize. Damian