slightly improved regex generation