It will not capture spaces after the decimal point. If this is unacceptable, feel free to optimize the regex. You can probably also reduce the number of inclusions at the top. I was just happy. I tested this in a file with a line of 1600, and it seems to have worked well with Qt 5.6
#include <QCoreApplication>
#include <QFile>
#include <QIODevice>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <QRegularExpressionMatchIterator>
#include <QString>
#include <QStringList>
#include <QTextStream>
int main(int argc, char * argv[])
{
QCoreApplication app(argc, argv);
QFile file("C:\\PathToFile\\bigFile.fileExt");
QStringList lines;
QStringList matches;
QString match;
file.open(QIODevice::ReadOnly | QIODevice::Text);
while(!file.atEnd())
{
lines << file.readLine();
}
file.close();
QRegularExpression regex("(^|\\s|,)\\K\\w.*?(?=(,|$))");
QRegularExpressionMatchIterator it;
foreach (QString element, lines)
{
it = regex.globalMatch(element);
while(it.hasNext())
{
QRegularExpressionMatch qre_match = it.next();
match = qre_match.captured(0);
matches << match;
}
}
return 0;
}
source
share