Fixing the regex matching in a more stable, correct way