A regular expression for a search query like: word1 * (word2 -word3 -word4) * word5

The question is what will be a regular expression to search for a sequence of words, excluding some words in a particular part of a string?

For example, to search for:

word1 * (word2 -word3 -word4) * word5

(where * means any number of any words, and -word means the word exception)

The corresponding lines will be:

word1 word99 word2 word98 word97 word5

word1 word2 word5

Does not match:

word1 word99 word2 word98 WORD4 word97 word5

word1 WORD3 word2 word5

PS It is designed to search in MySQL using the REGEXP operator.

+4
source share
2 answers

You cannot do this with REGEXP, you must create a FULLTEXT index in your column and look for FULLTEXT by performing a search. In BOOLEAN MODE will provide you with all the necessary functions.

+1
source

Try using Sphinx, it has the necessary functions.

+1
source

All Articles