6.0.0-rc4Source

QRegularExpressionMatch Class

The QRegularExpressionMatch class provides the results of matching a QRegularExpression against a string. More…

Header#include <QRegularExpressionMatch>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since5.0

List of all members, including inherited members

Public Functions

QRegularExpressionMatch()
QRegularExpressionMatch(const QRegularExpressionMatch &match)
QRegularExpressionMatch(QRegularExpressionMatch &&match)
~QRegularExpressionMatch()
QRegularExpressionMatch &operator=(const QRegularExpressionMatch &match)
QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match)
voidswap(QRegularExpressionMatch &other)
QRegularExpressionregularExpression() const
QRegularExpression::MatchTypematchType() const
QRegularExpression::MatchOptionsmatchOptions() const
boolhasMatch() const
boolhasPartialMatch() const
boolisValid() const
intlastCapturedIndex() const
boolhasCaptured(int nth) const
boolhasCaptured(QStringView name) const
QStringcaptured(int nth = 0) const
QStringcaptured(QStringView name) const
QStringViewcapturedView(int nth = 0) const
QStringViewcapturedView(QStringView name) const
QStringListcapturedTexts() const
qsizetypecapturedStart(int nth = 0) const
qsizetypecapturedLength(int nth = 0) const
qsizetypecapturedEnd(int nth = 0) const
qsizetypecapturedStart(QStringView name) const
qsizetypecapturedLength(QStringView name) const
qsizetypecapturedEnd(QStringView name) const

Detailed Description

A match object reports whether the expression matched, and the text and position of each capturing group. Groups are numbered from 1 in the order of their opening parentheses; group 0 is the whole match. Named groups can also be looked up by name.

See also QRegularExpression and QRegularExpressionMatchIterator.

Differences from Qt

The match keeps its own copy of the subject string, so capturedView() refers into that copy and stays valid as long as the match object.

Member Function Documentation

QRegularExpressionMatch::QRegularExpressionMatch()

Constructs a valid match object that has no match. Its match type is QRegularExpression::NoMatch.

QRegularExpressionMatch::QRegularExpressionMatch(const QRegularExpressionMatch &match)

Constructs a copy of match.

QRegularExpressionMatch::QRegularExpressionMatch(QRegularExpressionMatch &&match)

Move-constructs a match from match, which is left without a match.

QRegularExpressionMatch::~QRegularExpressionMatch()

Destroys the match.

QString QRegularExpressionMatch::captured(int nth = 0) const

Returns the text captured by group nth, or a null QString if the group did not capture or does not exist. Group 0 is the whole match.

See also capturedView(), capturedStart() and capturedTexts().

QString QRegularExpressionMatch::captured(QStringView name) const

This is an overloaded function.

Returns the text captured by the group called name, or a null QString.

qsizetype QRegularExpressionMatch::capturedEnd(int nth = 0) const

Returns the position just after the text captured by group nth, or -1 if the group did not capture.

See also capturedStart() and capturedLength().

qsizetype QRegularExpressionMatch::capturedEnd(QStringView name) const

This is an overloaded function.

Returns the end of the text captured by the group called name, or -1.

qsizetype QRegularExpressionMatch::capturedLength(int nth = 0) const

Returns the length of the text captured by group nth, or 0 if the group did not capture.

See also capturedStart() and capturedEnd().

qsizetype QRegularExpressionMatch::capturedLength(QStringView name) const

This is an overloaded function.

Returns the length of the text captured by the group called name.

qsizetype QRegularExpressionMatch::capturedStart(int nth = 0) const

Returns the start of the text captured by group nth in the subject, or -1 if the group did not capture.

See also capturedEnd() and capturedLength().

qsizetype QRegularExpressionMatch::capturedStart(QStringView name) const

This is an overloaded function.

Returns the start of the text captured by the group called name, or -1.

QStringList QRegularExpressionMatch::capturedTexts() const

Returns the texts captured by groups 0 to lastCapturedIndex(). Groups that did not capture give null strings.

See also captured().

QStringView QRegularExpressionMatch::capturedView(int nth = 0) const

Returns a view of the text captured by group nth, or a null view. The view refers into the match object's copy of the subject.

This function was introduced in 5.10.

See also captured().

QStringView QRegularExpressionMatch::capturedView(QStringView name) const

This is an overloaded function.

Returns a view of the text captured by the group called name.

This function was introduced in 5.10.

bool QRegularExpressionMatch::hasCaptured(int nth) const

Returns true if group nth captured something, even an empty string; otherwise returns false.

This function was introduced in 6.3.

See also captured() and lastCapturedIndex().

bool QRegularExpressionMatch::hasCaptured(QStringView name) const

This is an overloaded function.

Returns true if the group called name captured something.

This function was introduced in 6.3.

bool QRegularExpressionMatch::hasMatch() const

Returns true if the expression matched completely; otherwise returns false.

See also hasPartialMatch().

bool QRegularExpressionMatch::hasPartialMatch() const

Returns true if the subject ended while the expression could still match (only for the partial match types); otherwise returns false. A partial match sets only group 0, from where the match started to the end of the subject.

See also hasMatch().

bool QRegularExpressionMatch::isValid() const

Returns true if the match was produced by a valid regular expression (or is a default-constructed match); otherwise returns false.

int QRegularExpressionMatch::lastCapturedIndex() const

Returns the index of the last group that captured something, 0 if only the whole match did, or -1 if there was no match.

See also captured() and hasCaptured().

QRegularExpression::MatchOptions QRegularExpressionMatch::matchOptions() const

Returns the match options used to produce this match.

QRegularExpression::MatchType QRegularExpressionMatch::matchType() const

Returns the match type used to produce this match.

QRegularExpressionMatch & QRegularExpressionMatch::operator=(const QRegularExpressionMatch &match)

Assigns match to this object and returns a reference to it.

QRegularExpressionMatch & QRegularExpressionMatch::operator=(QRegularExpressionMatch &&match)

Move-assigns match to this object and returns a reference to it.

QRegularExpression QRegularExpressionMatch::regularExpression() const

Returns the regular expression that produced this match.

void QRegularExpressionMatch::swap(QRegularExpressionMatch &other)

Swaps this match with other.