From 824c726340ed8da0393aa97016682bcfd8c8bdc3 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sun, 27 Dec 2020 15:27:42 +0200 Subject: QRegularExpression: mention raw string literal in the docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Raw string literals (since C++11 according to [1]), make writing/reading regex patterns easier, since one can just use e.g. "\w\d" without having to escape those backslashes e.g. "\\w\\d"; this is especially useful with longer/more complex regex patterns. [1] https://en.cppreference.com/w/cpp/language/string_literal Pick-to: 5.15 6.0 Change-Id: I119f9566d27222b915af931ee7e13e064baede61 Reviewed-by: Giuseppe D'Angelo Reviewed-by: André Hartmann --- .../doc/snippets/code/src_corelib_text_qregularexpression.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/corelib/doc/snippets/code') diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qregularexpression.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qregularexpression.cpp index c418a1f279..8bf67a9e2d 100644 --- a/src/corelib/doc/snippets/code/src_corelib_text_qregularexpression.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_text_qregularexpression.cpp @@ -357,6 +357,8 @@ QString wildcard = QRegularExpression::wildcardToRegularExpression("*.jpeg"); { //! [34] +// using a raw string literal, R"(raw_characters)", to be able to use "\w" +// without having to escape the backslash as "\\w" QRegularExpression re(R"(\w+)"); QString subject("the quick fox"); for (const QRegularExpressionMatch &match : re.globalMatch(subject)) { @@ -364,4 +366,12 @@ for (const QRegularExpressionMatch &match : re.globalMatch(subject)) { } //! [34] } + +{ +//! [35] +// matches two digits followed by a space and a word +QRegularExpression re(R"(\d\d \w+)"); +//! [35] +} + } -- cgit v1.2.3