I want to filter out ${...}
with a QRegExp
, such that it retuns a QStringList
of all selected elements:
"${NAME}" << "${DAY}" << "${MEH}" << "${MEH}" << "${MEH}"
but somehow it doesn't work:
QString text = "Hello ${NAME} \
How is your ${DAY} so? \
Bye, ${MEH} ${MEH}\
${MEH}";
// Regex: /(\${.*})/g
QRegExp rx("/(\\${.*})/g");
QStringList list;
int pos = 0;
while ((pos = rx.indexIn(text, pos)) != -1) {
QString val = rx.cap(1);
list << val;
qDebug () << "Val: " << val;
pos += rx.matchedLength();
}
No output at all? What I am doing wrong?
Update:
QRegularExpression
works, but only on a per-line and not per-entry level. Ideas?
QString text = "Hello ${NAME} \
How is your ${DAY} so? \
Bye, ${MEH} ${MEH}\
${MEH}";
QRegularExpression rx("(\\${.*})");
QRegularExpressionMatchIterator i = rx.globalMatch(text);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
qDebug() << "Value: " << match.captured(0);
}
Output:
Value: "${NAME} \t\t\tHow is your ${DAY} so? \t\t\tBye, ${MEH} ${MEH}\t\t\t${MEH}"