improved regex matching