The old QRegExp class does not support the non-greedy operator .*?, you need to call QRegExp::setMinimal(true) for that. Also, you are supposed to iterate over the captured texts:
r.setMinimal(true);
int pos = 0;
while ((pos = r.indexIn(myText, pos)) != -1)
{
qDebug() << r.cap(1);
pos += r.matchedLength();
}
QRegExp r("\\{(.*)\\}");
r.setMinimal(true);
int pos = 0;
while ((pos = r.indexIn(myText, pos)) != -1)
{
qDebug() << r.cap(1);
pos += r.matchedLength();
}
To copy to clipboard, switch view to plain text mode
If you are working with Qt 5, you can use the new QRegularExpression:
QRegularExpression r("\\{(.*?)\\}");
QRegularExpressionMatchIterator i = r.globalMatch(myText);
while (i.hasNext())
{
QRegularExpressionMatch match = i.next();
qDebug() << match.captured(1);
}
QRegularExpression r("\\{(.*?)\\}");
QRegularExpressionMatchIterator i = r.globalMatch(myText);
while (i.hasNext())
{
QRegularExpressionMatch match = i.next();
qDebug() << match.captured(1);
}
To copy to clipboard, switch view to plain text mode
Bookmarks