QRegularExpressionMatch¶
The QRegularExpressionMatch
class provides the results of a matching a QRegularExpression
against a string. More…
Synopsis¶
Functions¶
def
captured
([nth=0])def
captured
(name)def
captured
(name)def
capturedEnd
([nth=0])def
capturedEnd
(name)def
capturedEnd
(name)def
capturedLength
([nth=0])def
capturedLength
(name)def
capturedLength
(name)def
capturedStart
([nth=0])def
capturedStart
(name)def
capturedStart
(name)def
capturedTexts
()def
capturedView
([nth=0])def
capturedView
(name)def
hasMatch
()def
hasPartialMatch
()def
isValid
()def
lastCapturedIndex
()def
matchOptions
()def
matchType
()def
regularExpression
()def
swap
(other)
Detailed Description¶
A QRegularExpressionMatch
object can be obtained by calling the 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:
re = QRegularExpression("(\\d\\d) (?\\w+)") match = re.match("23 Jordan") if match.hasMatch(): number = match.captured(1) # first == "23" 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.
See also
- class PySide6.QtCore.QRegularExpressionMatch¶
PySide6.QtCore.QRegularExpressionMatch(match)
- Parameters
Constructs a valid, empty QRegularExpressionMatch
object. The regular expression is set to a default-constructed one; the match type to NoMatch
and the match options to NoMatchOption
.
The object will report no match through the hasMatch()
and the hasPartialMatch()
member functions.
- PySide6.QtCore.QRegularExpressionMatch.captured(name)¶
- Parameters
name –
QStringView
- Return type
str
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 QString
.
See also
capturedView()
capturedStart()
capturedEnd()
capturedLength()
isNull()
- PySide6.QtCore.QRegularExpressionMatch.captured(name)
- Parameters
name – str
- Return type
str
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 QString
.
See also
capturedView()
capturedStart()
capturedEnd()
capturedLength()
isNull()
- PySide6.QtCore.QRegularExpressionMatch.captured([nth=0])
- Parameters
nth – int
- Return type
str
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 QString
.
Note
The implicit capturing group number 0 captures the substring matched by the entire pattern.
See also
capturedView()
lastCapturedIndex()
capturedStart()
capturedEnd()
capturedLength()
isNull()
- PySide6.QtCore.QRegularExpressionMatch.capturedEnd(name)¶
- Parameters
name –
QStringView
- Return type
qsizetype
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
- PySide6.QtCore.QRegularExpressionMatch.capturedEnd(name)
- Parameters
name – str
- Return type
qsizetype
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
- PySide6.QtCore.QRegularExpressionMatch.capturedEnd([nth=0])
- Parameters
nth – int
- Return type
qsizetype
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
- PySide6.QtCore.QRegularExpressionMatch.capturedLength(name)¶
- Parameters
name –
QStringView
- Return type
qsizetype
Returns the length of the substring captured by the capturing group named name
.
Note
This function returns 0 if the capturing group named name
did not capture a string or doesn’t exist.
See also
- PySide6.QtCore.QRegularExpressionMatch.capturedLength(name)
- Parameters
name – str
- Return type
qsizetype
Returns the length of the substring captured by the capturing group named name
.
Note
This function returns 0 if the capturing group named name
did not capture a string or doesn’t exist.
See also
- PySide6.QtCore.QRegularExpressionMatch.capturedLength([nth=0])
- Parameters
nth – int
- Return type
qsizetype
Returns the length of the substring captured by the nth
capturing group.
Note
This function returns 0 if the nth
capturing group did not capture a string or doesn’t exist.
See also
- PySide6.QtCore.QRegularExpressionMatch.capturedStart([nth=0])¶
- Parameters
nth – int
- Return type
qsizetype
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
- PySide6.QtCore.QRegularExpressionMatch.capturedStart(name)
- Parameters
name – str
- Return type
qsizetype
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
- PySide6.QtCore.QRegularExpressionMatch.capturedStart(name)
- Parameters
name –
QStringView
- Return type
qsizetype
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
- PySide6.QtCore.QRegularExpressionMatch.capturedTexts()¶
- Return type
list of strings
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.
- PySide6.QtCore.QRegularExpressionMatch.capturedView(name)¶
- Parameters
name –
QStringView
- Return type
QStringView
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 QStringView
.
See also
captured()
capturedStart()
capturedEnd()
capturedLength()
isNull()
- PySide6.QtCore.QRegularExpressionMatch.capturedView([nth=0])
- Parameters
nth – int
- Return type
QStringView
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 QStringView
.
Note
The implicit capturing group number 0 captures the substring matched by the entire pattern.
See also
captured()
lastCapturedIndex()
capturedStart()
capturedEnd()
capturedLength()
isNull()
- PySide6.QtCore.QRegularExpressionMatch.hasMatch()¶
- Return type
bool
Returns true
if the regular expression matched against the subject string, or false otherwise.
See also
- PySide6.QtCore.QRegularExpressionMatch.hasPartialMatch()¶
- Return type
bool
Returns true
if the regular expression partially matched against the subject string, or false otherwise.
Note
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 hasMatch()
will return true.
See also
match()
MatchType
hasMatch()
- PySide6.QtCore.QRegularExpressionMatch.isValid()¶
- Return type
bool
Returns true
if the match object was obtained as a result from the match()
function invoked on a valid QRegularExpression
object; returns false
if the QRegularExpression
was invalid.
- PySide6.QtCore.QRegularExpressionMatch.lastCapturedIndex()¶
- Return type
int
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:
match = re.match(string) for i in range(0, match.lastCapturedIndex() + 1): captured = match.captured(i) # ...
Note that some of the capturing groups with an index less than could have not matched, and therefore captured nothing.
If the regular expression did not match, this function returns -1.
- PySide6.QtCore.QRegularExpressionMatch.matchOptions()¶
- Return type
MatchOptions
Returns the match options that were used to get this QRegularExpressionMatch
object, that is, the match options that were passed to match()
or globalMatch()
.
See also
Returns the match type that was used to get this QRegularExpressionMatch
object, that is, the match type that was passed to match()
or globalMatch()
.
See also
- PySide6.QtCore.QRegularExpressionMatch.regularExpression()¶
- Return type
Returns the QRegularExpression
object whose match() function returned this object.
See also
- PySide6.QtCore.QRegularExpressionMatch.swap(other)¶
- Parameters
Swaps the match result other
with this match result. This operation is very fast and never fails.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.