Page 1 of 1

QRegularExpression possible bug ?

Posted: Fri Feb 04 2022 1:20 am
by FullAlquimista
Hi!

I was trying to make this code works and notice something about it...

Code: Select all

QRegularExpression expressaoNomes("[\\w\\d-*]+"); // This pattern does not match. But WHY ?!?
//QRegularExpression expressaoNomes("[\\w\\d*-]+"); // This pattern does match.
QString str = QString::fromUtf8("asdf*");
auto m = expressaoNomes.match(str);
if(m.hasMatch())
  spdlog::info("{}", m.captured().toStdString());
The culpriti was the order of the caracters "-*" for "*-". I don´t know why but the caracter '-' is treat diferent from a plain caracter that it would be when inside the [...] thing...

Sorry about my english.
The version of Copperspice that I am using is 1.7.2 compiled with MinGW 11.2.0 X64 with ICU 69.1 and OpenSSL 1.1.1l.

Re: QRegularExpression possible bug ?

Posted: Sat Feb 05 2022 9:21 pm
by ansel
FullAlquimista wrote: Fri Feb 04 2022 1:20 am The culpriti was the order of the caracters "-*" for "*-". I don´t know why but the caracter '-' is treat diferent from a plain caracter that it would be when inside the [...] thing...

The version of Copperspice that I am using is 1.7.2 compiled with MinGW 11.2.0 X64 with ICU 69.1 and OpenSSL 1.1.1l.
Thanks for your question.

Yes, the '-' character is treated differently in a character class. A character class is a group of characters within square brackets.

As an example, the character class '[A-Z]' matches every letter from A to Z, whereas '[AZ-]' matches only the letters A, Z, and '-'. For additional information, please take a look at the QRegularExpression documentation about Character Classes:

https://www.copperspice.com/docs/cs_api/class_qregularexpression.html#details

Re: QRegularExpression possible bug ?

Posted: Sun Feb 06 2022 1:12 am
by FullAlquimista
Thanks ansel!

I will be looking in to the docs. For now I will be putting the '-' character in the end of square brackets.