View Full Version : advances search with QRegExp
solook
19th May 2011, 16:43
hi ..
how I can do advances search with QRegExp..
if i write "word(?=\s+word2)" just line 2 return true :
1-word false
2-word word2 true
3-word word1 word2 false
my questions is how can i write to "word word1 word2" be true ?
and if write word(?!=\s+word2) "word word1 word2" is still true but how can i write to be false and only "word" be true?
Santosh Reddy
19th May 2011, 20:03
Will this work for you
QRegExp exp("*word*word2*");
exp.setPatternSyntax(QRegExp::Wildcard);
exp.exactMatch("word") ? "true" : "false"); //false
exp.exactMatch("word word2") ? "true" : "false"); //true
exp.exactMatch("word word1 word2") ? "true" : "false"); //true
exp.exactMatch("word word2 word1") ? "true" : "false"); //true
exp.exactMatch("word0 word2 word1") ? "true" : "false"); //true
solook
19th May 2011, 20:47
thanks ..
how can set unwanted word ?
for example the like not have word4
Santosh Reddy
19th May 2011, 21:59
Here this may a better solutionfor you, without wildcards.
QRegExp exp("word\\s(?!word4).*word2.*");
exp.exactMatch("word") ? "true" : "false"); //false
exp.exactMatch("word word2") ? "true" : "false"); //true
exp.exactMatch("word word1 word2") ? "true" : "false"); //true
exp.exactMatch("word word2 word1") ? "true" : "false"); //true
exp.exactMatch("word0 word2 word1") ? "true" : "false"); //false
exp.exactMatch("word word4 word2 word1") ? "true" : "false"); //false
MarekR22
20th May 2011, 09:27
but he want to use lookahead and match only "word".
This is quite simple fix you excretion like this (\b means word border):
\bword\b(?=.*\bword2\b)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.