将PCRE正则表达式转换为mysql查询正则表达式 [英] convert PCRE regular expression to mysql query regular expression

查看:193
本文介绍了将PCRE正则表达式转换为mysql查询正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的正则表达式如下

^(?!\d+$)(?!(?:[^$&%@]*[$&%@]){4})(?!.*\b\w{11}).{3,}$

在PHP中运行正常

我希望将其转换为MySQL支持的查询.当我在正则表达式之上运行时.我从reg-exp收到错误重复操作符操作数无效"

I want that converted to MySQL supported query. when I run above regular expression. I got error 'repetition-operator operand invalid' from reg-exp

请帮助解决此问题

推荐答案

MySQL不支持环视,也不支持\d\w类.您可以这样分割正则表达式:

MySQL does not support lookarounds, nor does it support \d or \w classes. You may split the regex like that:

SELECT * FROM table WHERE col REGEXP '^.{3,}$' AND col NOT REGEXP '^[0-9]+$' AND col NOT REGEXP '([^$&%@]*[$&%@]){4}' AND col NOT REGEXP '[[:<:]][[:alnum:]_]{11}'

位置:

  • REGEXP '^.{3,}$'-总长度应为3个或更多字符
  • AND col NOT REGEXP '^[0-9]+$'-字符串不能仅包含数字
  • AND col NOT REGEXP '([^$&%@]*[$&%@]){4}'-字符串不能包含4个特殊字符
  • AND col NOT REGEXP '[[:alnum:]_]{11}'-字符串不能包含11个字符的单词
  • REGEXP '^.{3,}$' - the total length should be 3 or more characters
  • AND col NOT REGEXP '^[0-9]+$' - string cannot consist of digits only
  • AND col NOT REGEXP '([^$&%@]*[$&%@]){4}' - string cannot have 4 special chars
  • AND col NOT REGEXP '[[:alnum:]_]{11}' - string cannot have a word with 11 chars

这篇关于将PCRE正则表达式转换为mysql查询正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆