Inconsistent regexp matching when using quantifiers?