diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp index ff83193152d..9d75caae91e 100644 --- a/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp +++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.cpp @@ -291,7 +291,7 @@ void RegularExpressionDialog::refresh() QRegularExpression::MatchOptions matchOptions = QRegularExpression::NoMatchOption; if (anchoredMatchOptionCheckBox->isChecked()) - matchOptions |= QRegularExpression::AnchoredMatchOption; + matchOptions |= QRegularExpression::AnchorAtOffsetMatchOption; if (dontCheckSubjectStringMatchOptionCheckBox->isChecked()) matchOptions |= QRegularExpression::DontCheckSubjectStringMatchOption; diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 003bc59e1c6..6544abb6465 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -553,7 +553,7 @@ QT_BEGIN_NAMESPACE \section2 Caret modes - The AnchoredMatchOption match option can be used to emulate the + The AnchorAtOffsetMatchOption match option can be used to emulate the QRegExp::CaretAtOffset behaviour. There is no equivalent for the other QRegExp::CaretMode modes. @@ -788,9 +788,16 @@ QT_BEGIN_NAMESPACE No match options are set. \value AnchoredMatchOption + Use AnchorAtOffsetMatchOption instead. + + \value AnchorAtOffsetMatchOption The match is constrained to start exactly at the offset passed to match() in order to be successful, even if the pattern string does not contain any metacharacter that anchors the match at that point. + Note that passing this option does not anchor the end of the match + to the end of the subject; if you want to fully anchor a regular + expression, use anchoredPattern(). + This enum value has been introduced in Qt 6.0. \value DontCheckSubjectStringMatchOption The subject string is not checked for UTF-16 validity before @@ -832,7 +839,7 @@ static int convertToPcreOptions(QRegularExpression::MatchOptions matchOptions) { int options = 0; - if (matchOptions & QRegularExpression::AnchoredMatchOption) + if (matchOptions & QRegularExpression::AnchorAtOffsetMatchOption) options |= PCRE2_ANCHORED; if (matchOptions & QRegularExpression::DontCheckSubjectStringMatchOption) options |= PCRE2_NO_UTF_CHECK; diff --git a/src/corelib/text/qregularexpression.h b/src/corelib/text/qregularexpression.h index 9e703a4eea6..9f618bf7f58 100644 --- a/src/corelib/text/qregularexpression.h +++ b/src/corelib/text/qregularexpression.h @@ -110,7 +110,8 @@ public: enum MatchOption { NoMatchOption = 0x0000, - AnchoredMatchOption = 0x0001, + AnchoredMatchOption Q_DECL_ENUMERATOR_DEPRECATED_X("Use AnchorAtOffsetMatchOption instead") = 0x0001, + AnchorAtOffsetMatchOption = 0x0001, DontCheckSubjectStringMatchOption = 0x0002 }; Q_DECLARE_FLAGS(MatchOptions, MatchOption) diff --git a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp index 83f9c17a428..a12fd636ebe 100644 --- a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp @@ -805,7 +805,7 @@ void tst_QRegularExpression::normalMatch_data() QTest::newRow("anchoredmatch01") << QRegularExpression("\\d+") << "abc123def" << 0 - << QRegularExpression::MatchOptions(QRegularExpression::AnchoredMatchOption) + << QRegularExpression::MatchOptions(QRegularExpression::AnchorAtOffsetMatchOption) << m; // *** @@ -1212,7 +1212,7 @@ void tst_QRegularExpression::globalMatch_data() << "ACA""GTG""CGA""AAA""AAA""AAG""GAA""AAG""AAA""AAA" << 0 << QRegularExpression::NormalMatch - << QRegularExpression::MatchOptions(QRegularExpression::AnchoredMatchOption) + << QRegularExpression::MatchOptions(QRegularExpression::AnchorAtOffsetMatchOption) << matchList; matchList.clear();