The QRegularExpression class in Qt 5 and 6 provides pattern matching using regular expressions. This tag is for questions about the use of regular expressions in the Qt library. For generic questions about regular expressions, use the "regex" tag.
The QRegularExpression
class provides pattern matching using regular expressions in the Qt framework.
The regular expression syntax in QRegularExpression
is modeled after Perl (PCRE).
Note: This class is new in Qt 5. Qt also offers an older, slightly less capable regex implementation though the QRegExp
class.
Usage example for finding all numbers in a string:
QRegularExpression re("(\\d+)");
QString str = "Offsets: 12 14 99 231 7";
QStringList list;
QRegularExpressionMatchIterator i = re.globalMatch(str);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
list << match.captured(1);
}
// list: ["12", "14", "99", "231", "7"]
Read on in the official Qt documentation for Qt 5.