c++qtqregexp

Regular expression of Qt don't match as expected


Why is the regular expression of Qt a little different? I can match correctly in regular matching software, but not in Qt. For example.

QString tstring = "scale(1.1) rotate(180) translate(1,0)";
QRegExp re("(?<=[\\)])."); 
QStringList tlist = tstring.split(re);

I want to separate the three with spaces to get the three QString "scale(1.1)", "rotate(180)" "translate(1,0)"


Solution

  • Different syntaxes of regular expressions exist. Qt implements some of them:

    Note that QRegularExpression is the recommended one:

    The QRegularExpression class introduced in Qt 5 is a big improvement upon QRegExp, in terms of APIs offered, supported pattern syntax and speed of execution.

    A detailed overview of the differences between QRegExp and QRegularExpression can be found in the docs.