Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
|
\inmodule QtCore \reentrant More...
#include <qregularexpression.h>
Public Member Functions | |
QRegularExpressionMatch () | |
~QRegularExpressionMatch () | |
Destroys the match result. | |
QRegularExpressionMatch (const QRegularExpressionMatch &match) | |
Constructs a match result by copying the result of the given match. | |
QRegularExpressionMatch (QRegularExpressionMatch &&match)=default | |
QRegularExpressionMatch & | operator= (const QRegularExpressionMatch &match) |
Assigns the match result match to this object, and returns a reference to the copy. | |
QRegularExpressionMatch & | operator= (QRegularExpressionMatch &&match) noexcept |
Move-assigns the match result match to this object, and returns a reference to the result. | |
void | swap (QRegularExpressionMatch &other) noexcept |
Swaps the match result other with this match result. | |
QRegularExpression | regularExpression () const |
Returns the QRegularExpression object whose match() function returned this object. | |
QRegularExpression::MatchType | matchType () const |
Returns the match type that was used to get this QRegularExpressionMatch object, that is, the match type that was passed to QRegularExpression::match() or QRegularExpression::globalMatch(). | |
QRegularExpression::MatchOptions | matchOptions () const |
Returns the match options that were used to get this QRegularExpressionMatch object, that is, the match options that were passed to QRegularExpression::match() or QRegularExpression::globalMatch(). | |
bool | hasMatch () const |
Returns true if the regular expression matched against the subject string, or false otherwise. | |
bool | hasPartialMatch () const |
Returns true if the regular expression partially matched against the subject string, or false otherwise. | |
bool | isValid () const |
Returns true if the match object was obtained as a result from the QRegularExpression::match() function invoked on a valid QRegularExpression object; returns false if the QRegularExpression was invalid. | |
int | lastCapturedIndex () const |
Returns the index of the last capturing group that captured something, including the implicit capturing group 0. | |
bool | hasCaptured (QAnyStringView name) const |
bool | hasCaptured (int nth) const |
QString | captured (int nth=0) const |
Returns the substring captured by the nth capturing group. | |
QStringView | capturedView (int nth=0) const |
QString | captured (QAnyStringView name) const |
QStringView | capturedView (QAnyStringView name) const |
QStringList | capturedTexts () const |
Returns a list of all strings captured by capturing groups, in the order the groups themselves appear in the pattern string. | |
qsizetype | 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. | |
qsizetype | capturedLength (int nth=0) const |
Returns the length of the substring captured by the nth capturing group. | |
qsizetype | 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. | |
qsizetype | capturedStart (QAnyStringView name) const |
qsizetype | capturedLength (QAnyStringView name) const |
qsizetype | capturedEnd (QAnyStringView name) const |
Friends | |
class | QRegularExpression |
struct | QRegularExpressionMatchPrivate |
class | QRegularExpressionMatchIterator |
Related Symbols | |
(Note that these are not member symbols.) | |
QDebug | operator<< (QDebug debug, const QRegularExpressionMatch &match) |
Writes the match object match into the debug object debug for debugging purposes. | |
\inmodule QtCore \reentrant
The QRegularExpressionMatch class provides the results of a matching a QRegularExpression against a string.
\keyword regular expression match
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:
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.
Definition at line 197 of file qregularexpression.h.
QRegularExpressionMatch::QRegularExpressionMatch | ( | ) |
Constructs a valid, empty QRegularExpressionMatch object. The regular expression is set to a default-constructed one; the match type to QRegularExpression::NoMatch and the match options to QRegularExpression::NoMatchOption.
The object will report no match through the hasMatch() and the hasPartialMatch() member functions.
Definition at line 2088 of file qregularexpression.cpp.
References QRegularExpressionMatchPrivate::isValid.
QRegularExpressionMatch::~QRegularExpressionMatch | ( | ) |
Destroys the match result.
Definition at line 2101 of file qregularexpression.cpp.
QRegularExpressionMatch::QRegularExpressionMatch | ( | const QRegularExpressionMatch & | match | ) |
Constructs a match result by copying the result of the given match.
Definition at line 2112 of file qregularexpression.cpp.
|
default |
Constructs a match result by moving the result from the given match.
Note that a moved-from QRegularExpressionMatch can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.
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 QString.
Definition at line 2293 of file qregularexpression.cpp.
References capturedView(), and QStringView::toString().
Referenced by capturedTexts(), QtAndroidFileDialogHelper::nameFilterExtensions(), and QGLXContext::queryDummyContext().
QString QRegularExpressionMatch::captured | ( | QAnyStringView | 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 QString.
Definition at line 2339 of file qregularexpression.cpp.
References capturedView(), qWarning, and QStringView::toString().
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.
Definition at line 2428 of file qregularexpression.cpp.
References QList< T >::at(), QRegularExpressionMatchPrivate::capturedOffsets, and hasCaptured().
Referenced by capturedEnd(), and capturedLength().
qsizetype QRegularExpressionMatch::capturedEnd | ( | QAnyStringView | 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.
Definition at line 2500 of file qregularexpression.cpp.
References capturedEnd(), QRegularExpressionPrivate::captureIndexForName(), qWarning, and QRegularExpressionMatchPrivate::regularExpression.
qsizetype QRegularExpressionMatch::capturedLength | ( | int | nth = 0 | ) | const |
Returns the length of the substring captured by the nth capturing group.
Definition at line 2415 of file qregularexpression.cpp.
References capturedEnd(), and capturedStart().
Referenced by capturedLength(), and capturedView().
qsizetype QRegularExpressionMatch::capturedLength | ( | QAnyStringView | name | ) | const |
Returns the length of the substring captured by the capturing group named name.
Definition at line 2475 of file qregularexpression.cpp.
References capturedLength(), QRegularExpressionPrivate::captureIndexForName(), qWarning, and QRegularExpressionMatchPrivate::regularExpression.
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.
Definition at line 2399 of file qregularexpression.cpp.
References QList< T >::at(), QRegularExpressionMatchPrivate::capturedOffsets, and hasCaptured().
Referenced by capturedLength(), capturedStart(), and capturedView().
qsizetype QRegularExpressionMatch::capturedStart | ( | QAnyStringView | 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.
Definition at line 2449 of file qregularexpression.cpp.
References capturedStart(), QRegularExpressionPrivate::captureIndexForName(), qWarning, and QRegularExpressionMatchPrivate::regularExpression.
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.
Definition at line 2382 of file qregularexpression.cpp.
References captured(), QRegularExpressionMatchPrivate::capturedCount, and i.
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 QStringView.
Definition at line 2312 of file qregularexpression.cpp.
References capturedLength(), capturedStart(), hasCaptured(), QStringView::mid(), and QRegularExpressionMatchPrivate::subject.
Referenced by captured(), captured(), capturedView(), and QMessagePattern::setPattern().
QStringView QRegularExpressionMatch::capturedView | ( | QAnyStringView | 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 QStringView.
Definition at line 2364 of file qregularexpression.cpp.
References capturedView(), QRegularExpressionPrivate::captureIndexForName(), qWarning, and QRegularExpressionMatchPrivate::regularExpression.
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).
Similarly, a capturing group may capture a substring of length 0; this function will return {true} for such a capturing group.
Definition at line 2273 of file qregularexpression.cpp.
References QList< T >::at(), QRegularExpressionMatchPrivate::capturedOffsets, and lastCapturedIndex().
bool QRegularExpressionMatch::hasCaptured | ( | QAnyStringView | 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).
Similarly, a capturing group may capture a substring of length 0; this function will return {true} for such a capturing group.
Definition at line 2245 of file qregularexpression.cpp.
References QRegularExpressionPrivate::captureIndexForName(), hasCaptured(), and QRegularExpressionMatchPrivate::regularExpression.
Referenced by capturedEnd(), capturedStart(), capturedView(), and hasCaptured().
bool QRegularExpressionMatch::hasMatch | ( | ) | const |
Returns true
if the regular expression matched against the subject string, or false otherwise.
Definition at line 2518 of file qregularexpression.cpp.
References QRegularExpressionMatchPrivate::hasMatch.
Referenced by QRegularExpressionMatchIteratorPrivate::hasNext().
bool QRegularExpressionMatch::hasPartialMatch | ( | ) | const |
Returns true
if the regular expression partially matched against the subject string, or false otherwise.
Definition at line 2533 of file qregularexpression.cpp.
References QRegularExpressionMatchPrivate::hasPartialMatch.
Referenced by QRegularExpressionMatchIteratorPrivate::hasNext().
bool QRegularExpressionMatch::isValid | ( | ) | const |
Returns true
if the match object was obtained as a result from the QRegularExpression::match() function invoked on a valid QRegularExpression object; returns false
if the QRegularExpression was invalid.
Definition at line 2545 of file qregularexpression.cpp.
References QRegularExpressionMatchPrivate::isValid.
Referenced by QRegularExpressionMatchIteratorPrivate::hasNext(), and QRegularExpressionMatchIterator::isValid().
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:
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.
Definition at line 2217 of file qregularexpression.cpp.
References QRegularExpressionMatchPrivate::capturedCount.
Referenced by hasCaptured().
QRegularExpression::MatchOptions QRegularExpressionMatch::matchOptions | ( | ) | const |
Returns the match options that were used to get this QRegularExpressionMatch object, that is, the match options that were passed to QRegularExpression::match() or QRegularExpression::globalMatch().
Definition at line 2198 of file qregularexpression.cpp.
References QRegularExpressionMatchPrivate::matchOptions.
QRegularExpression::MatchType QRegularExpressionMatch::matchType | ( | ) | const |
Returns the match type that was used to get this QRegularExpressionMatch object, that is, the match type that was passed to QRegularExpression::match() or QRegularExpression::globalMatch().
Definition at line 2186 of file qregularexpression.cpp.
References QRegularExpressionMatchPrivate::matchType.
QRegularExpressionMatch & QRegularExpressionMatch::operator= | ( | const QRegularExpressionMatch & | match | ) |
Assigns the match result match to this object, and returns a reference to the copy.
Definition at line 2135 of file qregularexpression.cpp.
References match().
|
inlinenoexcept |
Move-assigns the match result match to this object, and returns a reference to the result.
Note that a moved-from QRegularExpressionMatch can only be destroyed or assigned to. The effect of calling other functions than the destructor or one of the assignment operators is undefined.
Definition at line 205 of file qregularexpression.h.
References d, match(), and swap().
QRegularExpression QRegularExpressionMatch::regularExpression | ( | ) | const |
Returns the QRegularExpression object whose match() function returned this object.
Definition at line 2173 of file qregularexpression.cpp.
References QRegularExpressionMatchPrivate::regularExpression.
|
inlinenoexcept |
Swaps the match result other with this match result.
This operation is very fast and never fails.
Definition at line 207 of file qregularexpression.h.
Referenced by operator=().
|
related |
Writes the match object match into the debug object debug for debugging purposes.
Definition at line 2837 of file qregularexpression.cpp.
References debug, i, and match().
|
friend |
Definition at line 264 of file qregularexpression.h.
|
friend |
Definition at line 266 of file qregularexpression.h.
|
friend |
Definition at line 265 of file qregularexpression.h.