QRegularExpression possible bug ?

Report any problems with CopperSpice
Post Reply
FullAlquimista
Posts: 10
Joined: Sun Jan 10 2021 11:24 pm

QRegularExpression possible bug ?

Post 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.
ansel
Posts: 152
Joined: Fri Apr 10 2015 8:23 am

Re: QRegularExpression possible bug ?

Post 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
Ansel Sermersheim
CopperSpice Cofounder
FullAlquimista
Posts: 10
Joined: Sun Jan 10 2021 11:24 pm

Re: QRegularExpression possible bug ?

Post 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.
Post Reply