On regex 101, I wrote the following regular expression:

^(\(|)*(\(|)*(\!|)[AZ](\)|)*((v|\^)(\!|)(\(|)*[AZ](\)|)*)*(v|\^)(\!|)[AZ](\)|)*$

and there everything is fine, it validates my string as it should.

here is my line:

D^!AvB^!(A^Bv(Av!C))v!CvB

but the problem is that when I insert a regular in Qt Creator, the same line does not pass validation. and the isValid() method returns true .

Well, a piece of code from Qt:

 QRegExp regExp("^(\(|)*(\(|)*(\!|)[AZ](\)|)*((v|\^)(\!|)(\(|)*[AZ](\)|)*)*(v|\^)(\!|)[AZ](\)|)*$"); if (regExp.isValid()){ cout << "is valid" << endl; } else { cout << regExp.errorString().toStdString() << endl; } cout << regExp.indexIn("D^!AvB^!(A^Bv(Av!C))v!CvB") << endl; // -1 

Perhaps in c ++ you cannot write as I wrote, but I do not know, because I do not write in c ++. Correct me where I was wrong.

    1 answer 1

    I haven't written in C ++ for a long time, but, apparently, here the screening is eaten by a string literal. It is worth trying instead of "\" to write "\\" to prevent this from happening.

    It is possible that there are other problems. Regular expressions do not work the same way everywhere, there are slight differences in different languages.

    • Thank you) "\\" helped) - Jester
    • You can also put R before the literal and the brackets around your regular season (R "(...)"), then you do not need to escape every bekslesh. (C ++ 11). - Vladimir Gamalyan