How to match every String behind ":"? For example: want to match "3.23423" in "roll:3.23423" or "true" in "smth:true".
Asked
Active
Viewed 1,844 times
-3
-
use a lookbehind `(?<=:)\S+` or `(?<=:).*` – Avinash Raj Sep 15 '14 at 14:36
-
(?<=:)\S+ or (?<=:).* doesn't work – user1824542 Sep 15 '14 at 15:07
1 Answers
2
Try this:
QRegExp rx("[a-z]+\:.+");
QString ss = "roll:3.23423";
int poss = 0;
while ((poss = rx.indexIn(ss, poss)) != -1) {
qDebug( )<< rx.cap(0).split(":").last();
poss += rx.matchedLength();
}
Output:
"3.23423"
But one man told me that split()
can be slow, so you can use also:
QRegExp rx("[a-z]+\:.+");
QString ss = "roll:3.23423";
int poss = 0;
while ((poss = rx.indexIn(ss, poss)) != -1) {
QString g = rx.cap(0);
int p = rx.cap(0).indexOf(":");
qDebug( )<< g.mid(p+1);
poss += rx.matchedLength();
}
It should be faster.
Update (before). Use this loop:
while ((poss = rx.indexIn(ss, poss)) != -1) {
QString g = rx.cap(0);
int p = rx.cap(0).lastIndexOf(":");
qDebug( )<< g.mid(0,p);
poss += rx.matchedLength();
}

Jablonski
- 18,083
- 2
- 46
- 47