convert PCRE regular expression to mysql query regular expression

前端 未结 2 2019
花落未央
花落未央 2021-01-16 13:03

I have below regular expression

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

it is working fine in PHP

I want

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 13:55

    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}'
    

    Where:

    • 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

提交回复
热议问题