Decode QString str(R"RX(...)RX") and explain what it is
-
Hi,
I started to learn
QRegularExpression
and I needed to write something like:QString str("Quotes " are not allowed");
but as you can see I cannot simply put quote symbol
"
to QString.
But I can do it in the following way:QString str(R"(Quotes " are not allowed)");
or:
QString str(R"RX(Quotes " are not allowed)RX");
Could someone explain what this
R
andRX
mean in this case? How to google that? -
R""()"" is a C++ raw string literal. RX in the last example is used as a delimiter to avoid false detection of the end of the literal.
https://en.cppreference.com/w/cpp/language/string_literal #6
-
Hi
As jeremy_k says it's a raw string literal which helps to avoid having to escape everything.
Before they came along one has to write it asQString str("\"Quotes \" are not allowed");
For regular expressions, this can fast becomes very clumsy and error-prone.
-
Hi,
Just in case, Qt provides a helper tool to help you write your regexps and test them.