我正在尝试从QString
中删除SQL
语句。所有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();
}
您可以使用
[^WA-Z]+
请参阅正则表达式演示。该模式仅匹配 1 个或多个非大写 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
//...
}