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?
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");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.