Skip to content

PythonQt.Qt.QRegularExpressionMatch

QRegularExpressionMatch

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

A QRegularExpressionMatch object can be obtained by calling the QRegularExpression::match() function, or as a single result of a global match from a QRegularExpressionMatchIterator.

The success or the failure of a match attempt can be inspected by calling the hasMatch() function. QRegularExpressionMatch also reports a successful partial match through the hasPartialMatch() function.

In addition, QRegularExpressionMatch 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 captured() 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 capturedStart() and the capturedEnd() function, respectively. The length of each captured substring is available using the capturedLength() function.

The convenience function capturedTexts() 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 QRegularExpression object the subject string was matched against by calling the regularExpression() function; the match type and the match options are available as well by calling the matchType() and the matchOptions() respectively.

Please refer to the QRegularExpression documentation for more information about the Qt regular expression classes.

Source: https://doc.qt.io/archives/qt-5.15/qregularexpressionmatch.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
captured function (self, name: Any) -> str X.captured(name) -> str (shared captured text)
capturedEnd function (self, name: Any) -> int X.capturedEnd(name) -> int (shared captured text)
capturedLength function (self, name: Any) -> int X.capturedLength(name) -> int (shared captured text)
capturedRef function (self, name: Any) -> str Returns a reference to the substring captured by the nth capturing group. (shared captured text)
capturedStart function (self, name: Any) -> int X.capturedStart(name) -> int (shared captured text)
capturedTexts function (self) -> tuple X.capturedTexts() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
hasMatch function (self) -> bool X.hasMatch() -> bool (shared captured text)
hasPartialMatch function (self) -> bool X.hasPartialMatch() -> bool (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
isValid function (self) -> bool X.isValid() -> bool (shared captured text)
lastCapturedIndex function (self) -> int X.lastCapturedIndex() -> int (shared captured text)
matchOptions function (self) -> Any Returns the match options that were used to get this [QRegularExpressionMatch](https://doc.qt.io/archives/qt-5.15/qregularexpressionmatch.html) object, that is, the match options that were passed to… (shared captured text)
matchType function (self) -> Any Returns the match type that was used to get this [QRegularExpressionMatch](https://doc.qt.io/archives/qt-5.15/qregularexpressionmatch.html) object, that is, the match type that was passed to… (shared captured text)
operator_assign function (self, match: Any) -> Any X.operator_assign(match) -> PythonQt.QtCore.QRegularExpressionMatch (shared captured text)
regularExpression function (self) -> Any X.regularExpression() -> PythonQt.QtCore.QRegularExpression (shared captured text)
swap function (self, other: Any) -> None Swaps the match result other with this match result. (shared captured text)