Mysql, PHP, searching for multiple words

前端 未结 5 1054
有刺的猬
有刺的猬 2021-01-23 05:11

I\'m trying to search a table for specific words.

Say I have a list of words: printer,network,wireless,urgent

I only want to return those rows where all of these

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-23 05:54

    Not sure this would work with MySQL regex engine but the regex (using lookarounds) below can achieve what you are looking for. Will find the words of interest irrespective of the order in which they occur:

    ^(?=.*printer)(?=.*network)(?=.*wireless)(?=.*urgent).*$
    

    Demo: http://www.rubular.com/r/XcVz5xMZcb

    Some regex lookaround examples here: http://www.rexegg.com/regex-lookarounds.html

提交回复
热议问题