qt正则替换()中内容
参考:http://doc.qt.io/qt-5/qregularexpression.html 参考:http://blog.sina.com.cn/s/blog_a6fb6cc90102vo7n.html
//实现1:替换()中内容 sOutputText = sPreOutputText.remove(QRegularExpression("([a-zA-Z*<>,0-9&nr=:]*)")); // 实现2:替换()中的内容 sOutputText = sPreOutputText."([^()]*)")); 注意:*匹配0-n次,+匹配1-n次,?匹配0-1次
其他样例1: // 输出串 QRegularExpression expr; expr.setPattern("[a-zA-Z]+"); QString strText = "static a static b static c"; QRegularExpressionMatch match = expr.match(strText); QStringList strList = match.capturedTexts(); QRegularExpressionMatchIterator iter = expr.globalMatch(strText); while (iter.hasNext()) { QRegularExpressionMatch tmpMatch = iter.next(); QStringList tmpLst = tmpMatch.capturedTexts(); }
qt提供的样例 Extracting captured substrings The QRegularExpressionMatch object contains also information aboutthe substrings captured by the capturing groups in the pattern string. Thecaptured() function will return the string captured by the n-th capturinggroup: QRegularExpressionre("^(dd)/(dd)/(dddd)$"); QRegularExpressionMatch match = re.match("08/12/1985"); if (match.hasMatch()) { QString day =match.captured(1); // day == "08" QString month =match.captured(2); // month == "12" QString year =match.captured(3); // year == "1985" // ... }
附:qt界面通常依赖: Qt5Core.dll Qt5Gui.dll Qt5Widgets.dll 另外依赖platfoms目录: platfomrs/qminimal.dll platforms/qoffscreen.dll platforms/qwindows.dll (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |