加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

qt正则替换()中内容

发布时间:2020-12-14 04:28:25 所属栏目:百科 来源:网络整理
导读:参考: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-9nr=:]*)" )); /

参考: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次

*

匹配前面的子表达式任意次。例如,zo*能匹配“z”“zo”以及“zoo”*等价于{0,}

+

匹配前面的子表达式一次或多次(大于等于1次)。例如,“zo+”能匹配“zo”以及“zoo”,但不能匹配“z”+等价于{1,}

?

匹配前面的子表达式零次或一次。例如,“do(es)?”可以匹配“do”“does”中的“do”?等价于{0,1}

{n}

n是一个非负整数。匹配确定的n次。例如,“o{2}”不能匹配“Bob”中的“o”,但是能匹配“food”中的两个o

{n,}

n是一个非负整数。至少匹配n次。例如,“o{2,}”不能匹配“Bob”中的“o”,但能匹配“foooood”中的所有o“o{1,}”等价于“o+”“o{0,}”则等价于“o*”

{n,m}

mn均为非负整数,其中n<=m。最少匹配n次且最多匹配m次。例如,“o{1,3}”将匹配“fooooood”中的前三个o“o{0,1}”等价于“o?”。请注意在逗号和两个数之间不能有空格。

将下一个字符标记为一个特殊字符、或一个原义字符、或一个向后引用、或一个八进制转义符。例如,“n”匹配n“n”匹配换行符。序列“”匹配“”“(”则匹配“(”。即相当于多种编程语言中都有的转义字符的概念。

^

匹配输入字符串的开始位置。如果设置了RegExp对象的Multiline属性,^也匹配“n”“r”之后的位置。

$

匹配输入字符串的结束位置。如果设置了RegExp对象的Multiline属性,$也匹配“n”“r”之前的位置。

.

匹配除“rn”之外的任何单个字符。要匹配包括“rn”在内的任何字符,请使用像“[sS]”的模式。

s

匹配任何不可见字符,包括空格、制表符、换页符等等。等价于[ fnrtv]

S

匹配任何可见字符。等价于[^ fnrtv]

[xyz]

字符集合。匹配所包含的任意一个字符。例如,“[abc]”可以匹配“plain”中的“a”

[^xyz]

负值字符集合。匹配未包含的任意字符。例如,“[^abc]”可以匹配“plain”中的“plin”

其他样例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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读