QString USES an interface for regular operations

  • 2020-06-19 11:26:23
  • OfStack

Describes the interface for QString to use regular operations.

Qt 5.0 introduced QRegularExpression, which fixes a lot of bugs compared to QRegExp and is also functionally compatible with QRegExp. QRegularExpression is recommended.

contains

If the regular expression rx matches somewhere in the string, the match returns true, or 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

Returns the number of times the regular expression rx matches in a string.


int count(const QRegExp &rx) const
int count(const QRegularExpression &re) const

indexOf

Returns the index position of the first match of the regular expression rx in the string, searched forward from the index position. If rx does not match anywhere, it returns -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

Returns the index position of the last 1 match of the regular expression rx in the string, searched backwards from the index position. If rx does not match anywhere, it returns -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

Removes a match in the string that matches the regular expression rx and returns a reference to the string.


QString &remove(const QRegExp &rx)
QString &remove(const QRegularExpression &re)

replace

Replace the string rx with after and return a reference to the string.


QString &replace(const QRegExp &rx, const QString &after)
QString &replace(const QRegularExpression &re, const QString &after)

section

A string is separated from a sequence of fields by a regular expression.


QString section(const QRegExp &reg, 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

Break the string into substrings matched by the regular expression rx and return a list of those strings.


QStringList split(const QRegExp &rx, QString::SplitBehavior behavior = KeepEmptyParts) const
QStringList split(const QRegularExpression &re, QString::SplitBehavior behavior = KeepEmptyParts) const

splitRef

Break the string into substring references matched by the regular expression rx and return a list of these strings.


QVector<QStringRef> splitRef(const QRegExp &rx, QString::SplitBehavior behavior = KeepEmptyParts) const
QVector<QStringRef> splitRef(const QRegularExpression &re, QString::SplitBehavior behavior = KeepEmptyParts) const

Related articles: