Vertical bar in your code is ok, but [a-z] is not "arbitraty word", for that you can use \w+ which means "any word character one or more times":
#include <QRegExp>
#include <QStringList>
#include <QDebug>
int main(){
QStringList str
= QStringList() <<
"G|word" <<
"_K|another" <<
"z|maybethis" <<
"P|this_one_for_sure" <<
"Z|!@#";
if (rx.indexIn(s) > -1){
qDebug() << rx.capturedTexts();
}
}
return 0;
}
#include <QRegExp>
#include <QStringList>
#include <QDebug>
int main(){
QRegExp rx("^([A-Z])\\|(\\w+)$");
QStringList str = QStringList() << "G|word" << "_K|another" << "z|maybethis" << "P|this_one_for_sure" << "Z|!@#";
foreach (QString s, str){
if (rx.indexIn(s) > -1){
qDebug() << rx.capturedTexts();
}
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks