4

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.

barbushin
  • 5,165
  • 5
  • 37
  • 43

2 Answers2

1

Try to use Sphinx, it has required features.

phparch
  • 175
  • 7
1

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.

nobody
  • 10,599
  • 4
  • 26
  • 43
  • I can't use FULL TEXT search because MySQL tables are on InnoDB engine. And anyway using FULL TEXT is not issue because there are no some REGEXP features that I need. – barbushin Sep 11 '11 at 08:42