Thanks Amleto
you need to use backreference to do it properly (as far as I can see), and even then I'm not sure if/how it would work.
I have not found much information about backreference so was not able to do it that.
Much simpler to just tokenise the search string and search for the tokens individually.
This is probably the easiest way to make it work. Here is how I made it work. The outcome will be that if searchable_string contains all search words, then hasAll will be true, else if searchable_string will have only some of the words, then hasAll will be false. Basically what it does, if one of the search words are not in searchable_text, then it stop looking for others and brings the result false.
bool hasAll = false;
for(int j(0);j<stl.count();++j)
{
hasAll
= searchable_string.
contains(QRegExp("\\b"+stl.
at(j
)+"\\b"));
if(!hasAll)
break;
}
QStringList stl = search_text.split("|");
bool hasAll = false;
for(int j(0);j<stl.count();++j)
{
hasAll = searchable_string.contains(QRegExp("\\b"+stl.at(j)+"\\b"));
if(!hasAll)
break;
}
To copy to clipboard, switch view to plain text mode
--------------
I have another question with QRegExp when searching, how do I set the reg expression to ignore non alphanumeric characters like these ,.<>;:'"\|[]{}!_-=+?/ ,
for example, if search text phrase is "this and"
it will return true if searchable_string is "you must get this, and not cry"
I can run
QString search_text
= ui
->lineEditSearch
->text
();
rx.setCaseSensitivity(Qt::CaseInsensitive);
rx.setPattern(search_text);
searchable_string.
replace(QRegExp("[+:;\\]\\[{}().,?/\\\"!'*-]"),
" ");
// replace non alphanumeric with white spacesearchable_string= searchable_string.simplified(); //remove extra white spaces
bool doesContain = searchable_string.contains(rx);
QString search_text = ui->lineEditSearch->text();
QRegExp rx;
rx.setCaseSensitivity(Qt::CaseInsensitive);
rx.setPattern(search_text);
searchable_string.replace(QRegExp("[+:;\\]\\[{}().,?/\\\"!'*-]")," "); // replace non alphanumeric with white space
searchable_string= searchable_string.simplified(); //remove extra white spaces
bool doesContain = searchable_string.contains(rx);
To copy to clipboard, switch view to plain text mode
this will return true, but the problem is that when I send rx to highlighter, it will not highlight the result(the results must contain original string, not the modifies that does not contain non alphanumeric charterers.
I need a way to ignore non alphanumeric characters without running replace() function.
Bookmarks