The QRegularExpressionMatch class provides the results of a matching a QRegularExpression 與字符串。 更多...
| 頭: | #include <QRegularExpressionMatch> |
| qmake: | QT += core |
| Since: | Qt 5.0 |
注意: 此類的所有函數 可重入 .
| QRegularExpressionMatch () | |
| QRegularExpressionMatch (const QRegularExpressionMatch & match ) | |
| ~QRegularExpressionMatch () | |
| QString | captured (int nth = 0) const |
| QString | captured (const QString & name ) const |
| int | capturedEnd (int nth = 0) const |
| int | capturedEnd (const QString & name ) const |
| int | capturedLength (int nth = 0) const |
| int | capturedLength (const QString & name ) const |
| QStringRef | capturedRef (int nth = 0) const |
| QStringRef | capturedRef (const QString & name ) const |
| int | capturedStart (int nth = 0) const |
| int | capturedStart (const QString & name ) const |
| QStringList | capturedTexts () const |
| bool | hasMatch () const |
| bool | hasPartialMatch () const |
| bool | isValid () const |
| int | lastCapturedIndex () const |
| QRegularExpression::MatchOptions | matchOptions () const |
| QRegularExpression::MatchType | matchType () const |
| QRegularExpression | regularExpression () const |
| void | swap (QRegularExpressionMatch & other ) |
| QRegularExpressionMatch & | operator= (const QRegularExpressionMatch & match ) |
| QRegularExpressionMatch & | operator= (QRegularExpressionMatch && match ) |
| QDebug | operator<< (QDebug debug , const QRegularExpressionMatch & match ) |
The QRegularExpressionMatch class provides the results of a matching a QRegularExpression 與字符串。
A QRegularExpressionMatch object can be obtained by calling the QRegularExpression::match () 函數,或作為全局匹配的單個結果來自 QRegularExpressionMatchIterator .
The success or the failure of a match attempt can be inspected by calling the hasMatch () 函數。 QRegularExpressionMatch also reports a successful partial match through the hasPartialMatch () 函數。
此外, 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 () 和 capturedEnd () function, respectively. The length of each captured substring is available using the capturedLength () 函數。
The convenience function
capturedTexts
() 會返迴
all
the captured substrings at once (including the substring matched by the entire pattern) in the order they have been captured by captring groups; that is,
captured(i) == capturedTexts().at(i)
.
可以檢索 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 () 和 matchOptions () 分彆。
請參考 QRegularExpression 文檔編製,瞭解有關 Qt 正則錶達式類的更多信息。
另請參閱 QRegularExpression .
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 () 和 hasPartialMatch () member functions.
該函數在 Qt 5.1 引入。
Constructs a match result by copying the result of the given match .
另請參閱 operator= ().
銷毀匹配結果。
返迴子字符串捕獲通過 nth capturing group. If the nth capturing group did not capture a string or doesn't exist, returns a null QString .
另請參閱 capturedRef (), lastCapturedIndex (), capturedStart (), capturedEnd (), capturedLength (),和 QString::isNull ().
Returns 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 a null QString .
另請參閱 capturedRef (), capturedStart (), capturedEnd (), capturedLength (),和 QString::isNull ().
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.
另請參閱 capturedStart (), capturedLength (),和 captured ().
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.
另請參閱 capturedStart (), capturedLength (),和 captured ().
Returns the length of the substring captured by the nth 捕獲組。
注意: This function returns 0 if the nth capturing group did not capture a string or doesn't exist.
另請參閱 capturedStart (), capturedEnd (),和 captured ().
Returns the offset inside the subject string corresponding to the starting position 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.
另請參閱 capturedStart (), capturedEnd (),和 captured ().
Returns a reference to the substring captured by the nth capturing group. If the nth capturing group did not capture a string or doesn't exist, returns a null QStringRef .
另請參閱 captured (), lastCapturedIndex (), capturedStart (), capturedEnd (), capturedLength (),和 QStringRef::isNull ().
Returns a reference to the string captured by the capturing group named name . If the capturing group named name did not capture a string or doesn't exist, returns a null QStringRef .
另請參閱 captured (), capturedStart (), capturedEnd (), capturedLength (),和 QStringRef::isNull ().
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.
另請參閱 capturedEnd (), capturedLength (),和 captured ().
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.
另請參閱 capturedEnd (), capturedLength (),和 captured ().
Returns a list of all strings captured by capturing groups, in the order the groups themselves appear in the pattern string.
返迴
true
if the regular expression matched against the subject string, or false otherwise.
另請參閱 QRegularExpression::match () 和 hasPartialMatch ().
返迴
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 hasMatch () will return true.
另請參閱 QRegularExpression::match (), QRegularExpression::MatchType ,和 hasMatch ().
返迴
true
if the match object was obtained as a result from the
QRegularExpression::match
() function invoked on a valid
QRegularExpression
對象;返迴
false
若
QRegularExpression
was invalid.
另請參閱 QRegularExpression::match () 和 QRegularExpression::isValid ().
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.
另請參閱 captured (), capturedStart (), capturedEnd (),和 capturedLength ().
Returns the match options that were used to get this QRegularExpressionMatch object, that is, the match options that were passed to QRegularExpression::match () 或 QRegularExpression::globalMatch ().
另請參閱 QRegularExpression::match (), regularExpression (),和 matchType ().
Returns the match type that was used to get this QRegularExpressionMatch object, that is, the match type that was passed to QRegularExpression::match () 或 QRegularExpression::globalMatch ().
另請參閱 QRegularExpression::match (), regularExpression (),和 matchOptions ().
返迴 QRegularExpression object whose match() function returned this object.
另請參閱 QRegularExpression::match (), matchType (),和 matchOptions ().
Swaps the match result other with this match result. This operation is very fast and never fails.
Assigns the match result match to this object, and returns a reference to the copy.
Move-assigns the match result match to this object, and returns a reference to the copy.
Writes the match object match 到 debug 對象 debug 為調試目的。
另請參閱 調試技術 .