0

I am porting some Qt5 code to Qt6, which requires switching QRegExp to QRegularExpression. The Qt5 code uses the setMinimal(bool minimal) method of QRegExp. Is there an equivalent PatternOption in Qt6?

I see a QRegularExpression::InvertedGreedinessOption PatternOption, but I don't really understand if this is equivalent.

TSG
  • 4,242
  • 9
  • 61
  • 121
  • Please provide a [mcve] demonstrating the required behaviour. As per the [documentation](https://doc.qt.io/qt-6/qregularexpression.html#details) `QRegularExpression` employs the Perl regular expression syntax outlined by [pcrepattern](https://man7.org/linux/man-pages/man3/pcrepattern.3.html). If you want all quantifiers to behave in a minimal/non-greedy manner then it might be best to do so explicitly using the `?` qualifier. – G.M. Jun 30 '23 at 18:06

1 Answers1

0

From Qt6 documentation, Minimal matching says:

QRegExp::setMinimal() implemented minimal matching by simply reversing the greediness of the quantifiers (QRegExp did not support lazy quantifiers, like *?, +?, etc.). QRegularExpression instead does support greedy, lazy, and possessive quantifiers.

The QRegularExpression::InvertedGreedinessOption pattern option can be useful to emulate the effects of QRegExp::setMinimal(): if enabled, it inverts the greediness of quantifiers (greedy ones become lazy and vice versa).