问题描述
我看到有一个新的正则表达式类 - QRegularExpression
。它只是一个typedef QRegExp,或一个新类,或什么?为什么我们需要它,我们已经有了QRegExp?
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?
推荐答案
真的是一个新类,它有改进,但它只在Qt5中可用,所以如果你想在Qt4和Qt5上编译,你不能使用它:
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:
QRegExpression在Qt 5中引入的QRegularExpression类是QRegExp的一个很大的改进,和执行速度。最大的区别是,当请求匹配时,QRegularExpression只保存正则表达式,并且不会修改。相反,返回QRegularExpressionMatch对象,以便检查匹配的结果并提取捕获的子字符串。这同样适用于全局匹配和QRegularExpressionMatchIterator。
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.
这篇关于QRegularExpression和QRegExp有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!