A sample regexp that could help you to extract data from files of the specified format (provided there are no extra features of the format you did not mention... as caduel said, a more precise grammar would help) :
QRegExp pattern
("\\s+&INDEX\\s+(?:(\\w+)=\\s*(\'[^\']+\'|\\S+)\\s+)+/")
QRegExp pattern("\\s+&INDEX\\s+(?:(\\w+)=\\s*(\'[^\']+\'|\\S+)\\s+)+/")
To copy to clipboard, switch view to plain text mode
You can match this regexp against every line of your input. If it matches then you can extract data using the list of capturedTexts() (item n is the attribute name (e.g Name or MAX in your example) and n+1 is the corresponding value, as a quoted string or a sequence of non-whitespace characters, n starting from 1) :
// supposing pattern has been matched against a string you can iterate as follow :
int max = pattern.numCaptures() - 1;
for ( int i = 1; i < max; i += 2 )
{
QString attributeName
= caps.
at(i
);
QString attributeValue
= caps.
at(i
+ 1);
// do something with that data now
}
// supposing pattern has been matched against a string you can iterate as follow :
int max = pattern.numCaptures() - 1;
QStringList caps = pattern.capturedTexts();
for ( int i = 1; i < max; i += 2 )
{
QString attributeName = caps.at(i);
QString attributeValue = caps.at(i + 1);
// do something with that data now
}
To copy to clipboard, switch view to plain text mode
Note : I have not tested this code so there might be a compilation error left but the principle is there.
Bookmarks