Hacker Timesnew | past | comments | ask | show | jobs | submit | boblauer's commentslogin

To answer your question, it's to give the appearance of fairness. It's the same reason Russia holds elections.


Counting capturing groups is a solved problem - http://stackoverflow.com/questions/16046620/regex-to-count-t...


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.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: