[英]convert PCRE regular expression to mysql query regular expression
I have below regular expression 我有以下正则表达式
^(?!\d+$)(?!(?:[^$&%@]*[$&%@]){4})(?!.*\b\w{11}).{3,}$
it is working fine in PHP 它在PHP中工作正常
I want that converted to MySQL supported query. 我希望将其转换为MySQL支持的查询。 when I run above regular expression. 当我在正则表达式之上运行时。 I got error 'repetition-operator operand invalid' from reg-exp 我从reg-exp中收到错误“重复运算符操作数无效”
please help to solve this 请帮助解决这个问题
MySQL does not support lookarounds, nor does it support \\d
or \\w
classes. MySQL不支持环视,也不支持\\d
或\\w
类。 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}'
Where: 哪里:
REGEXP '^.{3,}$'
- the total length should be 3 or more characters REGEXP '^.{3,}$'
-总长度应为3个或更多字符 AND col NOT REGEXP '^[0-9]+$'
- string cannot consist of digits only AND col NOT REGEXP '^[0-9]+$'
-字符串不能仅包含数字 AND col NOT REGEXP '([^$&%@]*[$&%@]){4}'
- string cannot have 4 special chars AND col NOT REGEXP '([^$&%@]*[$&%@]){4}'
-字符串不能包含4个特殊字符 AND col NOT REGEXP '[[:alnum:]_]{11}'
- string cannot have a word with 11 chars AND col NOT REGEXP '[[:alnum:]_]{11}'
-字符串中的单词不能包含11个字符 The work around is to use preg-like MySQL UDF Library that has more complex REGEXP than the native MySQL's own. 解决方法是使用类似preg的MySQL UDF库,该库具有比本机MySQL自己的REGEXP更复杂的REGEXP。
https://github.com/mysqludf/lib_mysqludf_preg https://github.com/mysqludf/lib_mysqludf_preg
and you can type the above in the link below to get Perl version of the expression that will work directly with the udf 并且您可以在下面的链接中键入上面的内容,以获得可以直接与udf一起使用的Perl版本的表达式
https://regex101.com/r/wU8uM7/22/codegen?language=javascript https://regex101.com/r/wU8uM7/22/codegen?language=javascript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.