convert PCRE regular expression to mysql query regular expression

前端 未结 2 2020
花落未央
花落未央 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:31

    The work around is to use preg-like MySQL UDF Library that has more complex REGEXP than the native MySQL's own.

    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

    https://regex101.com/r/wU8uM7/22/codegen?language=javascript

    0 讨论(0)
  • 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
    0 讨论(0)
提交回复
热议问题