Regular expression for search query like: word1 * (word2 -word3 -word4) * word5

+4 votes
asked Sep 11, 2011 by barbushin

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

For example, for search request:

word1 * (word2 -word3 -word4) * word5

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

Matched strings will be:

word1 word99 word2 word98 word97 word5

word1 word2 word5

Not matched:

word1 word99 word2 word98 WORD4 word97 word5

word1 WORD3 word2 word5

P.S. It's for search in MySQL using REGEXP operator.

2 Answers

+1 vote
answered Sep 11, 2011 by nobody

You will not be able to do that with REGEXP, you should create a FULLTEXT index on your column and do FULLTEXT searches, doing the searches IN BOOLEAN MODE will give you all the features you want.

+1 vote
answered Jun 18, 2012 by phparch

Try to use Sphinx, it has required features.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter