setMinimal equivalent in QRegularExpression

149 Views Asked by At

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.

1

There are 1 best solutions below

0
A.R.M On

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).