Fixed handling of subexpressions

Previously, subexpressions were always consumed greedily, resulting in valid strings not matching.