News for hackers. Stuff that matters.

boblauer

To answer your question, it's to give the appearance of fairness. It's the same reason Russia holds elections.
Re:Node.js in Flame Graphs on Thursday November 20, 2014 @04:34PM (#8638295)
Counting capturing groups is a solved problem - http://stackoverflow.com/questions/16046620/regex-to-count-t...
Re:Node.js in Flame Graphs on Thursday November 20, 2014 @04:32PM (#8638284)
You can get the index of the match via the .exec function. It returns an array. The first element is the match, and then an element for each capturing group. You'd need to keep track of how many sub-capturing groups each individual top-level capturing group has, but that's not terribly difficult.

As far as multiple matches, after you found a match, you would then test against a new regex that is everything to the right of the previous regex's captured group.

((a)|(b)|(c)|(d)) -> if b matches, you then test against ((c)|(d)), and so on.