diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-03-27 13:19:15 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-04-07 11:52:01 +0000 |
commit | f497dea73080c2d8910bd5b6d74c9a6226db0c92 (patch) | |
tree | 5b823d7982065697c4ffc69e581ee3a3fc98ee6c /src/corelib/tools/qregularexpression.cpp | |
parent | ac76b2424d323ad7eed0238116366587b742d93f (diff) |
Doc: Clarify the porting notes from QRegExp to QRegularExpression
Add a small table to illustrate the results exactMatch() and split
out the part on partial matching to a separate section since it
is less common.
Change-Id: Ifbd5c3cbd1d8c0ee9e8b2d58ed13f40776b03762
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'src/corelib/tools/qregularexpression.cpp')
-rw-r--r-- | src/corelib/tools/qregularexpression.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index f1fac093b0..88b696f53a 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -445,19 +445,25 @@ QT_BEGIN_NAMESPACE Other differences are outlined below. - \section2 Exact matching + \section2 Porting from QRegExp::exactMatch() QRegExp::exactMatch() in Qt 4 served two purposes: it exactly matched a regular expression against a subject string, and it implemented partial - matching. In fact, if an exact match was not found, one could still find - out how much of the subject string was matched by the regular expression - by calling QRegExp::matchedLength(). If the returned length was equal - to the subject string's length, then one could desume that a partial match - was found. + matching. - QRegularExpression supports partial matching explicitly by means of the - appropriate MatchType. If instead you simply want to be sure that the - subject string matches the regular expression exactly, you can wrap the + \section3 Porting from QRegExp's Exact Matching + + Exact matching indicates whether the regular expression matches the entire + subject string. For example, the classes yield on the subject string \c{"abc123"}: + + \table + \header \li \li QRegExp::exactMatch() \li QRegularExpressionMatch::hasMatch() + \row \li \c{"\\d+"} \li \b false \li \b true + \row \li \c{"[a-z]+\\d+"} \li \b true \li \b true + \endtable + + Exact matching is not reflected in QRegularExpression. If you want to be + sure that the subject string matches the regular expression exactly, you can wrap the pattern between a couple of anchoring expressions. Simply putting the pattern between the \c{^} and the \c{$} anchors is enough in most cases: @@ -479,6 +485,17 @@ QT_BEGIN_NAMESPACE Note the usage of the non-capturing group in order to preserve the meaning of the branch operator inside the pattern. + \section3 Porting from QRegExp's Partial Matching + + When using QRegExp::exactMatch(), if an exact match was not found, one + could still find out how much of the subject string was matched by the + regular expression by calling QRegExp::matchedLength(). If the returned length + was equal to the subject string's length, then one could conclude that a partial + match was found. + + QRegularExpression supports partial matching explicitly by means of the + appropriate MatchType. + \section2 Global matching Due to limitations of the QRegExp API it was impossible to implement global |