Is there any difference between QRegularExpression and QRegExp?

sashoalm picture sashoalm · Apr 9, 2015 · Viewed 10.8k times · Source

I see there is a new class for regular expressions - QRegularExpression. Is it just a typedef for QRegExp, or a new class, or what? And why do we need it, we already have QRegExp?

Answer

sashoalm picture sashoalm · Apr 9, 2015

Ok, after some more digging into the docs, I found it really is a new class, it has improvements, but it is only available in Qt5, so you can't use it if you want to compile on both Qt4 and Qt5:

Notes for QRegExp Users

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. The biggest difference is that QRegularExpression simply holds a regular expression, and it's not modified when a match is requested. Instead, a QRegularExpressionMatch object is returned, in order to check the result of a match and extract the captured substring. The same applies with global matching and QRegularExpressionMatchIterator.