I have the following input:
(&xxx-&yyyy) &pp_pp+&uuu
I'm trying to get all matches which starts with an & and are followed by any word character.
E.g. above should yield to:
&xxx
&yyyy
&pp_pp
&uuu
What I tried is:
QRegExp rx;
rx.setPattern("(&\\w+)+");
rx.indexIn("(&xxx-&yyyy) &pp_pp+&uuu");
QStringList variables;
for(int i = 1; i < rx.captureCount(); i++)
{
variables.append(rx.cap(i));
}
I just don't get any match. Where is my mistake?
If I have the above input rx.captureCount() is always 1.
I don't think it's my regex which is wrong, because I checked it on http://regexpal.com/ and there it worked.
Solved it by using:
QStringList list;
int pos = 0;
while ((pos = rx.indexIn(str, pos)) != -1) {
list << rx.cap(1);
pos += rx.matchedLength();
}