Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trouble with QRegExp
Qt 6.11 is out! See what's new in the release blog

Trouble with QRegExp

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 831 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bronstein87
    wrote on last edited by
    #1

    I tested this pattern:
    QRegExp rx = QRegExp("^(?!ТЕСТ-М[^\S*\d*]).*$");
    With these 3 words:
    qDebug() << rx.indexIn("привет") << rx.indexIn("ТЕСТ-М60") << rx.indexIn("ТЕСТ-М");
    And all of them were matched, but, for example here:
    regex
    and at all other platforms pattern has another behavior, third word match to it. Why it happends? What i'm doing wrong ?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2
      1. you are not escaping the \. Either use double slash (\\) or use raw string literals
      2. All 3 of those strings match your pattern, if you tell us what you are trying to do maybe we can fix it. By guessing I'd say you need to replace the [^\S*\d*] with a negative look-ahead
      3. QRegExp is deprecated in Qt5, you should use QRegularExpression if you can

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      5
      • B Offline
        B Offline
        bronstein87
        wrote on last edited by bronstein87
        #3

        Hi. Thanks for your reply. I can't use QRegularExpression because i need to filter column with QSortFilterProxyModel and it doesn't support this class. Ok, maybe you can help me. For example, i have 4 words "TEST", "TEST-M60", "TEST МF", "TEST-M60/1000" and i need to write excluding pattern, which allows me, for example, hide rows with "TEST-M60" and see all others and so on.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          subclass QSortFilterProxyModel like below

          class NegativeSortFilterProxyModel : public QSortFilterProxyModel{
              Q_OBJECT
              Q_DISABLE_COPY(NegativeSortFilterProxyModel)
          public:
              explicit NegativeSortFilterProxyModel(QObject* parent = Q_NULLPTR) : QSortFilterProxyModel(parent) {}
          protected:
              bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const Q_DECL_OVERRIDE{
                  return !QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
              }
          };
          

          now use NegativeSortFilterProxyModel::setFilterRegExp("TEST-M60"); to hide all the TEST-M60

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved