dsizmmwnm56437180 2016-03-14 14:10
浏览 36

正则表达式负向前瞻匹配,而它不应该

Good day. I'm using the following regex to restrain users from adding "bad" stuff in a MySQL query.

$regex = "/\s+where(?:\s+([a-z]\w*\.?\w*)\s*=\s*(?!\1)\'?\w*\'?(?:\s*and)?)+\s*(?:order\s+by|limit|$)/uix";

Thing is, when trying the following query - it still matches:

$query = "UPDATE test set is_active = 1 where id = id ";
var_dump(preg_match($regex, $query));die;
//int(1)

What's even more strange, i've tried to test and debug this regex using online tools like this,this, and regexr.com, and everywhere the regex does not match the query. Am i missing some flag or setting or something?

edit: did not escape the \1 properly because was using double quotes. Thank you goldfish from the regex101 chat :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记