QRegularExpressionMatch Class▲
-
Header: QRegularExpressionMatch
-
Since: Qt 5.0
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
-
qmake: QT += core
-
Group: QRegularExpressionMatch is part of tools, https://
Detailed Description▲
A https:// object can be obtained by calling the https://() function, or as a single result of a global match from a https://.
The success or the failure of a match attempt can be inspected by calling the https://() function. https:// also reports a successful partial match through the https://() function.
In addition, https:// returns the substrings captured by the capturing groups in the pattern string. The implicit capturing group with index 0 captures the result of the whole match. The https://() function returns each substring captured, either by the capturing group's index or by its name:
QRegularExpression re("(\\d\\d) (?<name>\\w+)");
QRegularExpressionMatch match = re.match("23 Jordan");
if (match.hasMatch()) {
QString number = match.captured(1); // first == "23"
QString name = match.captured("name"); // name == "Jordan"
}For each captured substring it is possible to query its starting and ending offsets in the subject string by calling the https://() and the https://() function, respectively. The length of each captured substring is available using the https://() function.
The convenience function https://() will return all the captured substrings at once (including the substring matched by the entire pattern) in the order they have been captured by capturing groups; that is, captured(i) == capturedTexts().at(i).
You can retrieve the https:// object the subject string was matched against by calling the https://() function; the match type and the match options are available as well by calling the https://() and the https://() respectively.
Please refer to the https:// documentation for more information about the Qt regular expression classes.
See Also▲
See also https://
Member Function Documentation▲
[since 6.3] bool QRegularExpressionMatch::hasCaptured(QStringView name) const▲
[since 6.3] bool QRegularExpressionMatch::hasCaptured(const QString &name) const
Returns true if the capturing group named name captured something in the subject string, and false otherwise (or if there is no capturing group called name).
Some capturing groups in a regular expression may not have captured anything even if the regular expression matched. This may happen, for instance, if a conditional operator is used in the pattern:
QRegularExpression re("([a-z]+)|([A-Z]+)");
QRegularExpressionMatch m = re.match("UPPERCASE");
if (m.hasMatch()) {
qDebug() << m.hasCaptured(0); // true
qDebug() << m.hasCaptured(1); // false
qDebug() << m.hasCaptured(2); // true
}Similarly, a capturing group may capture a substring of length 0; this function will return true for such a capturing group.
This function was introduced in Qt 6.3.
See Also▲
See also https://(), https://()
[since 5.1] QRegularExpressionMatch::QRegularExpressionMatch()▲
Constructs a valid, empty https:// object. The regular expression is set to a default-constructed one; the match type to https:// and the match options to https://.
The object will report no match through the https://() and the https://() member functions.
This function was introduced in Qt 5.1.
QRegularExpressionMatch::QRegularExpressionMatch(const QRegularExpressionMatch &match)▲
[since 6.1] QRegularExpressionMatch::QRegularExpressionMatch(QRegularExpressionMatch &&match)▲
Constructs a match result by moving the result from the given match.
Note that a moved-from https:// can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.
This function was introduced in Qt 6.1.
See Also▲
See also https://()
QRegularExpressionMatch::~QRegularExpressionMatch()▲
Destroys the match result.
QString QRegularExpressionMatch::captured(int nth = 0) const▲
Returns the substring captured by the nth capturing group.
If the nth capturing group did not capture a string, or if there is no such capturing group, returns a null https://.
The implicit capturing group number 0 captures the substring matched by the entire pattern.
See Also▲
See also https://(), https://(), https://(), https://(), https://(), https://()
QString QRegularExpressionMatch::captured(const QString &name) const▲
Returns the substring captured by the capturing group named name.
If the named capturing group name did not capture a string, or if there is no capturing group named name, returns a null https://.
See Also▲
See also https://(), https://(), https://(), https://(), https://()
[since 5.10] QString QRegularExpressionMatch::captured(QStringView name) const▲
Returns the substring captured by the capturing group named name.
If the named capturing group name did not capture a string, or if there is no capturing group named name, returns a null https://.
This function was introduced in Qt 5.10.
See Also▲
See also https://(), https://(), https://(), https://(), https://()
qsizetype QRegularExpressionMatch::capturedEnd(int nth = 0) const▲
Returns the offset inside the subject string immediately after the ending position of the substring captured by the nth capturing group. If the nth capturing group did not capture a string or doesn't exist, returns -1.
See Also▲
See also https://(), https://(), https://()
qsizetype QRegularExpressionMatch::capturedEnd(const QString &name) const▲
Returns the offset inside the subject string immediately after the ending position of the substring captured by the capturing group named name. If the capturing group named name did not capture a string or doesn't exist, returns -1.
See Also▲
See also https://(), https://(), https://()
[since 5.10] qsizetype QRegularExpressionMatch::capturedEnd(QStringView name) const▲
Returns the offset inside the subject string immediately after the ending position of the substring captured by the capturing group named name. If the capturing group named name did not capture a string or doesn't exist, returns -1.
This function was introduced in Qt 5.10.
See Also▲
See also https://(), https://(), https://()
qsizetype QRegularExpressionMatch::capturedLength(int nth = 0) const▲
Returns the length of the substring captured by the nth capturing group.
This function returns 0 if the nth capturing group did not capture a string or doesn't exist.
See Also▲
See also https://(), https://(), https://()
qsizetype QRegularExpressionMatch::capturedLength(const QString &name) const▲
Returns the length of the substring captured by the capturing group named name.
This function returns 0 if the capturing group named name did not capture a string or doesn't exist.
See Also▲
See also https://(), https://(), https://()
[since 5.10] qsizetype QRegularExpressionMatch::capturedLength(QStringView name) const▲
Returns the length of the substring captured by the capturing group named name.
This function returns 0 if the capturing group named name did not capture a string or doesn't exist.
This function was introduced in Qt 5.10.
See Also▲
See also https://(), https://(), https://()
qsizetype QRegularExpressionMatch::capturedStart(int nth = 0) const▲
Returns the offset inside the subject string corresponding to the starting position of the substring captured by the nth capturing group. If the nth capturing group did not capture a string or doesn't exist, returns -1.
See Also▲
See also https://(), https://(), https://()
qsizetype QRegularExpressionMatch::capturedStart(const QString &name) const▲
Returns the offset inside the subject string corresponding to the starting position of the substring captured by the capturing group named name. If the capturing group named name did not capture a string or doesn't exist, returns -1.
See Also▲
See also https://(), https://(), https://()
[since 5.10] qsizetype QRegularExpressionMatch::capturedStart(QStringView name) const▲
Returns the offset inside the subject string corresponding to the starting position of the substring captured by the capturing group named name. If the capturing group named name did not capture a string or doesn't exist, returns -1.
This function was introduced in Qt 5.10.
See Also▲
See also https://(), https://(), https://()
QStringList QRegularExpressionMatch::capturedTexts() const▲
Returns a list of all strings captured by capturing groups, in the order the groups themselves appear in the pattern string. The list includes the implicit capturing group number 0, capturing the substring matched by the entire pattern.
[since 5.10] QStringView QRegularExpressionMatch::capturedView(int nth = 0) const▲
Returns a view of the substring captured by the nth capturing group.
If the nth capturing group did not capture a string, or if there is no such capturing group, returns a null https://.
The implicit capturing group number 0 captures the substring matched by the entire pattern.
This function was introduced in Qt 5.10.
See Also▲
See also https://(), https://(), https://(), https://(), https://(), https://()
[since 5.10] QStringView QRegularExpressionMatch::capturedView(QStringView name) const▲
Returns a view of the string captured by the capturing group named name.
If the named capturing group name did not capture a string, or if there is no capturing group named name, returns a null https://.
This function was introduced in Qt 5.10.
See Also▲
See also https://(), https://(), https://(), https://(), https://()
[since 6.3] bool QRegularExpressionMatch::hasCaptured(int nth) const▲
Returns true if the nth capturing group captured something in the subject string, and false otherwise (or if there is no such capturing group).
The implicit capturing group number 0 captures the substring matched by the entire pattern.
Some capturing groups in a regular expression may not have captured anything even if the regular expression matched. This may happen, for instance, if a conditional operator is used in the pattern:
QRegularExpression re("([a-z]+)|([A-Z]+)");
QRegularExpressionMatch m = re.match("UPPERCASE");
if (m.hasMatch()) {
qDebug() << m.hasCaptured(0); // true
qDebug() << m.hasCaptured(1); // false
qDebug() << m.hasCaptured(2); // true
}Similarly, a capturing group may capture a substring of length 0; this function will return true for such a capturing group.
This function was introduced in Qt 6.3.
See Also▲
See also https://(), https://(), https://()
bool QRegularExpressionMatch::hasMatch() const▲
Returns true if the regular expression matched against the subject string, or false otherwise.
See Also▲
See also https://(), https://()
bool QRegularExpressionMatch::hasPartialMatch() const▲
Returns true if the regular expression partially matched against the subject string, or false otherwise.
Only a match that explicitly used the one of the partial match types can yield a partial match. Still, if such a match succeeds totally, this function will return false, while https://() will return true.
See Also▲
See also https://(), https://, https://()
bool QRegularExpressionMatch::isValid() const▲
Returns true if the match object was obtained as a result from the https://() function invoked on a valid https:// object; returns false if the https:// was invalid.
See Also▲
See also https://(), https://()
int QRegularExpressionMatch::lastCapturedIndex() const▲
Returns the index of the last capturing group that captured something, including the implicit capturing group 0. This can be used to extract all the substrings that were captured:
QRegularExpressionMatch match = re.match(string);
for (int i = 0; i <= match.lastCapturedIndex(); ++i) {
QString captured = match.captured(i);
// ...
}Note that some of the capturing groups with an index less than lastCapturedIndex() could have not matched, and therefore captured nothing.
If the regular expression did not match, this function returns -1.
See Also▲
See also https://(), https://(), https://(), https://(), https://()
QRegularExpression::MatchOptions QRegularExpressionMatch::matchOptions() const▲
Returns the match options that were used to get this https:// object, that is, the match options that were passed to https://() or https://().
See Also▲
See also https://(), https://(), https://()
QRegularExpression::MatchType QRegularExpressionMatch::matchType() const▲
Returns the match type that was used to get this https:// object, that is, the match type that was passed to https://() or https://().
See Also▲
See also https://(), https://(), https://()
QRegularExpression QRegularExpressionMatch::regularExpression() const▲
Returns the https:// object whose match() function returned this object.
See Also▲
See also https://(), https://(), https://()
void QRegularExpressionMatch::swap(QRegularExpressionMatch &other)▲
Swaps the match result other with this match result. This operation is very fast and never fails.
QRegularExpressionMatch &QRegularExpressionMatch::operator=(const QRegularExpressionMatch &match)▲
Assigns the match result match to this object, and returns a reference to the copy.
QRegularExpressionMatch &QRegularExpressionMatch::operator=(QRegularExpressionMatch &&match)▲
Move-assigns the match result match to this object, and returns a reference to the result.
Note that a moved-from https:// can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.


