Important: Please read the Qt Code of Conduct -

5.12 RegExpr Unicode Support

  • Does Qt 5.12 support the following?

    objRegExp =/^[\p{L}\p{N}-]{3,30}$/u
    return objRegExp.test(inputString)

    I can get this to work fine on but I'm concerned ECMAScript versions might not be high enough in 5.12 for /p{...} support. If not, can someone describe a good method to localize a [a-zA-Z0-9] type regular expression?


  • @rhb327
    I don't know the answer. But I recently discovered Qt comes with interactive QRegularExpression UI checker sample code at Takes one minute to download & compile, useful from then onward for whatever version of Qt you are using.

  • Thanks! Link was helpful. I decided to move away from QML and I created a C++ support class kinda like this:

        qmlRegisterType<RegEx_Qml>("REQML", 1, 0, "RegEx_Qml");
        RegEx_Qml* reQML = new RegEx_Qml();
        engine->rootContext()->setContextProperty("reQML", reQML);
    #ifndef REGEX_QML_H
    #define REGEX_QML_H
    #include <QObject>
    #include <QRegularExpression>
    #include "constants.h"
    class RegEx_Qml : public QObject {
        Q_PROPERTY(QString valString READ valString WRITE setValString NOTIFY valStringChanged);
        explicit RegEx_Qml(QObject* parent = nullptr);
        Q_INVOKABLE bool test(QString tst_str);
        void valStringChanged(QString valString);
        QString valString() const { return m_valString; }
        void setValString(QString s) {
            m_valString = s;
            emit valStringChanged(m_valString);
        QString m_valString;
        QRegularExpression regExp;
    #endif // REGEX_QML_H
    RegEx_Qml::RegEx_Qml(QObject* parent) : QObject(parent) {
    RegEx_Qml::~RegEx_Qml() {
    bool RegEx_Qml::test(QString tst_str) {
        QRegularExpressionMatch mtch = regExp.match(tst_str, 0);
        qDebug() << "RegEx: " << tst_str << m_valString << regExp.match(tst_str, 0) << mtch.isValid() << mtch.hasMatch();
        if(mtch.isValid()) {
            return mtch.hasMatch();
        else {
            return false;

    QML Interface

                    RegEx_Qml {
                        id: regExQml
                    // validate Text fields with respect to strIndex
                    function validateInputData(inputIndex, inputString){
                        var objRegExp
                        switch(inputIndex) {
                        case 0 :
                            regExQml.valString = "^[\\w\\d.-]{4,20}$"
                            return regExQml.test(inputString)
                        case 1 :
                            console.log("Validating inputs for Pwd: ", usermodel_AddUser.get(0).labelText,usermodel_AddUser.count)
                            if(usermodel_AddUser.get(0).labelText==="Test" || usermodel_AddUser.get(0).labelText==="service"){
                                regExQml.valString = "^[\\w\\d.-]{4,20}$"
                                return regExQml.test(inputString)

Log in to reply