I'm trying to get with a QRegularExpression all attributes of an xml tag in the different captured groups. I use a regex matching the tags and I manage to get the capture groups containing the attribute value but with a quantifier, I get only the last one.
I use this regex :
<[a-z]+(?: [a-z]+=("[^"]*"))*>
And I would like to get "a" and "b" with this text :
<p a="a" b="b">
Here is the code:
const QString text { "<p a=\"a\" b=\"b\">" };
const QRegularExpression pattern { "<[a-z]+(?: [a-z]+=(\"[^\"]*\"))*>" };
QRegularExpressionMatchIterator it = pattern.globalMatch(text);
while (it.hasNext())
{
const QRegularExpressionMatch match = it.next();
qDebug() << "Match with" << match.lastCapturedIndex() + 1 << "captured groups";
for (int i { 0 }; i <= match.lastCapturedIndex(); ++i)
qDebug() << match.captured(i);
}
And the output :
Match with 2 captured groups
"<p a=\"a\" b=\"b\">"
"\"b\""
Is it possible to get multiple capture groups with the quantifier *
or have I to iterate using QRegularExpressionMatchIterator
with a specific regex on the string literals?