我正在尝试从SQL
中删除QString
语句。所有SQL
指令均为大写。我希望只有列名全部小写,下划线作为名称中的空格。作为示例,QString
可能包含:
CREATE TABLE IF NOT EXISTS activated_alerts(id INTEGER PRIMARY KEY AUTOINCREMENT, date_and_time TEXT, system_state TEXT, alarm_no_185 BOOL NOT NULL, alarm_no_4 BOOL NOT NULL, alarm_no_5 BOOL NOT NULL, alarm_no_2 BOOL NOT NULL, alarm_no_102 BOOL NOT NULL, alarm_no_7 BOOL NOT NULL, alarm_no_27 BOOL NOT NULL, alarm_no_120 BOOL NOT NULL, alarm_no_103 BOOL NOT NULL, alarm_no_190 BOOL NOT NULL, alarm_no_30 BOOL NOT NULL, alarm_no_31 BOOL NOT NULL, alarm_no_32 BOOL NOT NULL, alarm_no_33 BOOL NOT NULL, alarm_no_34 BOOL NOT NULL, alarm_no_35 BOOL NOT NULL)
我尝试了^[A-Z]+$
,但我得到了零匹配。
QRegularExpression re("^[A-Z]+$");
QRegularExpressionMatch match = re.match(m_activatedAlertsSQLStatement);
if(match.hasMatch())
{
qDebug() << "CAPTURED: " << match.capturedTexts();
}
答案 0 :(得分:0)
您可以使用
[^\WA-Z]+
请参阅regex demo。该模式只匹配一个或多个不是大写ASCII字母的单词字符。
Qt示例演示:
QRegularExpression re("[^\\WA-Z]+");
QString subject("YOUR_STRING");
QRegularExpressionMatchIterator i = re.globalMatch(subject);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
qDebug() << "CAPTURED: " << match.captured(0); // Print match value
//...
}