Important: Please read the Qt Code of Conduct -

Condition in QRegExp

  • The following code is does not work. Why?
    QRegExp *reg = new QRegExp("(?(x)y|z)"); // pattern: (?(if)then|else)
    qDebug() << reg->exactMatch("xy"); // return 'false'

  • try qDebug() << reg->isValid(); to see if the pattern is correct.

    Also I think the "?" should be at the end of the pattern.. Might be wrong, didn't use qregexp with ? as of yet

  • One thing you might want to try out is the regexp example. For learning a bit more of regexp and its behaviour it is quite handy.
    Check on *\examples\widgets\tools\regexp for Qt5.1.0 for Qt 4 it was under *\examples\tools\regexp

Log in to reply