Match everything in a single re.match, use more reliable group detection

* use a regexp match to establish the number of capturing groups in a regexp

* match all options & groups at once for speed