Search for QRegExp in a QString
I have a tabbed interface in my application. I am getting the contents of the focused tab in a string variable as
QString myString = currentTab->getTextEdit()->toPlainText();
Now, I want to search this string for the occurrence of some other strings which I have defined as a regular expression and for each occurrence, I want to prepend a character to the occurrence. Please let me know how to find every occurrence of regular expression in myString.
Re: Search for QRegExp in a QString
Re: Search for QRegExp in a QString
Using indexOf() I am able to prepend the required character only to the first occurrence of the RegExp in myString. How can I do the same for all the occurrences??
Re: Search for QRegExp in a QString
Quote:
Originally Posted by
Abc
How can I do the same for all the occurrences??
Invoke indexOf() once more, but this time use the second parameter and return value to skip the previous occurence.
Re: Search for QRegExp in a QString
This does not work if there are multiple occurrences of the same RegExp and it is not even known how amny times a particular RegExp would occur. How can I find multiple occurrences and make the required change??
Re: Search for QRegExp in a QString
did you see this example?
Code:
QString str
= "Offsets: 12 14 99 231 7";
int pos = 0;
while ((pos = rx.indexIn(str, pos)) != -1) {
list << rx.cap(1);
pos += rx.matchedLength();
}
Re: Search for QRegExp in a QString