QString使用正則操作的接口實(shí)現(xiàn)
介紹QString使用正則操作的接口。
Qt 5.0引入QRegularExpression,相比于QRegExp,前者修復(fù)了很多bugs,功能上也是兼容于QRegExp。推薦使用QRegularExpression。
contains
正則表達(dá)式rx是否與字符串中的某個(gè)地方匹配,匹配返回true,否則返回false。
bool contains(const QRegExp &rx) const bool contains(QRegExp &rx) const bool contains(const QRegularExpression &re) const bool contains(const QRegularExpression &re, QRegularExpressionMatch *match) const
count
返回正則表達(dá)式rx在字符串中匹配的次數(shù)。
int count(const QRegExp &rx) const int count(const QRegularExpression &re) const
indexOf
返回字符串中正則表達(dá)式rx的第一個(gè)匹配項(xiàng)的索引位置,從索引位置向前搜索。如果rx在任何地方都不匹配,則返回-1。
int indexOf(QRegExp &rx, int from = 0) const int indexOf(const QRegularExpression &re, int from = 0) const int indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const
lastIndexOf
返回字符串中正則表達(dá)式rx最后一個(gè)匹配項(xiàng)的索引位置,從索引位置向后搜索。如果rx在任何地方都不匹配,則返回-1。
int lastIndexOf(QRegExp &rx, int from = -1) const int lastIndexOf(const QRegularExpression &re, int from = -1) const int lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const
remove
移除字符串中符合正則表達(dá)式rx的匹配,并返回對(duì)該字符串的引用。
QString &remove(const QRegExp &rx) QString &remove(const QRegularExpression &re)
replace
將字符串中符合正則表達(dá)式rx就替換為after字符串,并返回對(duì)該字符串的引用。
QString &replace(const QRegExp &rx, const QString &after) QString &replace(const QRegularExpression &re, const QString &after)
section
將字符串由正則表達(dá)式來(lái)分割字段序列。
QString section(const QRegExp ®, int start, int end = -1, QString::SectionFlags flags = SectionDefault) const QString section(const QRegularExpression &re, int start, int end = -1, QString::SectionFlags flags = SectionDefault) const
split
將字符串拆分為正則表達(dá)式rx匹配的子字符串,并返回這些字符串的列表。
QStringList split(const QRegExp &rx, QString::SplitBehavior behavior = KeepEmptyParts) const QStringList split(const QRegularExpression &re, QString::SplitBehavior behavior = KeepEmptyParts) const
splitRef
將字符串拆分為正則表達(dá)式rx匹配的子字符串引用,并返回這些字符串的列表。
QVector<QStringRef> splitRef(const QRegExp &rx, QString::SplitBehavior behavior = KeepEmptyParts) const QVector<QStringRef> splitRef(const QRegularExpression &re, QString::SplitBehavior behavior = KeepEmptyParts) const
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C語(yǔ)言實(shí)現(xiàn)折半查找法(二分法)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)折半查找法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11
C/C++高精度(加減乘除)算法的實(shí)現(xiàn)
高精度的算法,一般的方式是用一個(gè)很長(zhǎng)的數(shù)組去記錄數(shù)據(jù),數(shù)組的每一位記錄固定位數(shù)的數(shù)字,記錄順序是低位到高位。本文將通過(guò)實(shí)例為大家介紹下高精度算法的實(shí)現(xiàn),感興趣的可以了解一下2022-12-12
淺談C++基類的析構(gòu)函數(shù)為虛函數(shù)
本文重點(diǎn):應(yīng)該為多態(tài)基類聲明虛析構(gòu)器。一旦一個(gè)類包含虛函數(shù),它就應(yīng)該包含一個(gè)虛析構(gòu)器。如果一個(gè)類不用作基類或者不需具有多態(tài)性,便不應(yīng)該為它聲明虛析構(gòu)器。2015-10-10
c語(yǔ)言 字符串轉(zhuǎn)大寫(xiě)的簡(jiǎn)單實(shí)例
這篇文章主要介紹了c語(yǔ)言 字符串轉(zhuǎn)大寫(xiě)的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下2013-12-12
C語(yǔ)言#define拼接宏定義實(shí)現(xiàn)方式
今天小編就為大家分享一篇C語(yǔ)言#define拼接宏定義實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12
C++靜態(tài)庫(kù)與動(dòng)態(tài)庫(kù)文件的生成和使用教程
庫(kù)文件是計(jì)算機(jī)上的一類文件,可以簡(jiǎn)單的把庫(kù)文件看成一種代碼倉(cāng)庫(kù),它提供給使用者一些可以直接拿來(lái)用的變量、函數(shù)和類,下面這篇文章主要給大家介紹了關(guān)于C++靜態(tài)庫(kù)與動(dòng)態(tài)庫(kù)文件的生成和使用的相關(guān)資料,需要的朋友可以參考下2023-03-03

