Search in Database with HTML Tags



  • At the moment i have a QTextEdit with Text that can be formatted. The whole Text i save with HTML Tags in the Database in a Text Field. That works find, because i can load the Text from the Database an put it again in the QTextEdit and its formatted.

    The only Problem is now, that i want to search in that Field for Words and show the Result in a QTableView. It works by the Way, but if i search for Tags like head, body or other HTML Things, all Entrys will be shown.

    Is there a Possibility to search in that Fields and ignore the HTML Thing? Maybe some RegEx Code, but it sounds difficult in the first Moment. An easier Way would be to save the Plaintext in an extra Field, but that sounds dirty.

    Anyone has an idea?


  • Qt Champions 2016

    Hi
    I think you can get pretty far with regular expressions
    alt text

    \b(\w+(?![^<>]*>))\b
    


  • The RegEx works nice, but i dont know how to implement it. This is what i try. QDebug always returns an empty string.

    QRegExp regex("\b(\w+(?![^<>]*>))\b");
                regex.indexIn(query.value(1).toString());
                QString str = regex.cap();
                qDebug () << str;
                if (str.contains(text))
                {
                    QList<QString> row;
                    row.append(query.value(0).toString());
                    row.append(query.value(1).toString());
                    row.append(query.value(2).toString());
                    row.append(query.value(3).toString());
                    row.append(query.value(4).toString());
                    row.append(query.value(5).toString());
                    data.append(row);
                }
    

  • Moderators

    @Fuel

    QRegExp is the older version within Qt. It is better to start with QRegularExpression

    There is an example given which can help you also in testing different regular expression with some text.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.