Logical AND operator in mySql REGEXP?

前端 未结 5 1631
名媛妹妹
名媛妹妹 2020-12-17 19:28

I use MySql REGEXP:

SELECT * FROM myTable
WHERE title REGEXP \"dog|cat|mouse\";

The dataset is small, so I am not concerned about performan

5条回答
  •  眼角桃花
    2020-12-17 19:39

    There's really no nice solution except concatenating ANDs:

    SELECT * FROM myTable
    WHERE title REGEXP "dog"
    AND title REGEXP "cat"
    AND title REGEXP "mouse"
    

    The regular expression would otherwise look like this:

    SELECT * FROM myTable
    WHERE title REGEXP "(dog.*cat.*mouse)|(dog.*mouse.*cat)|(mouse.*dog.*cat)|(mouse.*cat.*dog)|(cat.*dog.*mouse)|(cat.*mouse.*dog)"
    

提交回复
热议问题