Slight logic error in regex