Hi,
What is the equalvalent function of
bool QTextEdit::find("TEST",QTextDocument::FindWholeWor ds)
in QString ?
Regards
Teh
Hi,
What is the equalvalent function of
bool QTextEdit::find("TEST",QTextDocument::FindWholeWor ds)
in QString ?
Regards
Teh
a life without programming is like an empty bottle![]()
One approach could be to use
int QString::indexOf ( const QRegExp & rx, int from = 0 ) const
and define the regexp to begin and end with a whitespace (\s).
To my mind you should use "\\b" instead of "\\s".Originally Posted by jpn
\b
A word boundary. For example the regexp \bOK\b means match immediately after a word boundary (e.g. start of string or whitespace) the letter 'O' then the letter 'K' immediately before another word boundary (e.g. end of string or whitespace). But note that the assertion does not actually match any whitespace so if we write (\bOK\b) and we have a match it will only contain 'OK' even if the string is "It's OK now".
Cesar, thanks for correcting. You're exactly right..
You're welcomeI hope that helped
hm..i think that bcteh_98 will be confused after read answers![]()
a life without programming is like an empty bottle![]()
Thank it work fine. But I still have a small problem.
regexp = \bOK\b
"I am OK_Now" Index of Match -1 ok fine
"I am (OK) Now" Index of Match 7 ok fine
"I am OK@Now" Index of Match 5 ok fine
=================================
"I am NOT-OK Now" Index of Match 9
"I am OK-Now" Index of Match 5
I don't want the last two result to match,
how to write a regular expressions to make it not Match -1.
Regards
Teh
Use a regexp of "[ \t\n]OK[ \t\n]". Or: "[^ \t\n]+" which will match a sequence of characters not containing a space, tab or newline in general.
I had to find words like @name_of_variable in css files (exactly qss file for a styleSheet setting). That's why I did not want to replace the wrong member! And so I had to find the members as whole words. For that I used:
Qt Code:
styleSheet = styleSheet.replace(QRegExp("[^a-zA-Z\\d_]" + name + "[^a-zA-Z\\d_]", Qt::CaseSensitive), " " + value + "; ");To copy to clipboard, switch view to plain text mode
Maybe it can helps someone!
Last edited by peter-70; 7th December 2018 at 09:05.
Bookmarks