Unsolved Trouble with QRegExp
-
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 ? -
- you are not escaping the
\
. Either use double slash (\\
) or use raw string literals - 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 QRegExp
is deprecated in Qt5, you should useQRegularExpression
if you can
- you are not escaping the
-
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.
-
subclass
QSortFilterProxyModel
like belowclass 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 theTEST-M60