Handle regexp patterns with subgroups.