Reputation: 2503
I know how to find regular expression in specific string. How to find first element that match with regular expression?
Here is my code:
QString mangledText;
QRegExp rx("string");
while ((pos = rx.indexIn(mangledText)) != -1){
mangledText.replace(pos, rx.matchedLength(), "replaced string");
}
I want to replace first match result (or second or third) instead of all of that.
Any suggestion?
Upvotes: 2
Views: 123
Reputation: 206567
I want to replace first match result instead of all of that.
Use an if
instead of a while
.
if ((pos = rx.indexIn(mangledText)) != -1){
mangledText.replace(pos, rx.matchedLength(), "replaced string");
}
Upvotes: 2