Actually there is such a pattern:

QRegExp rx = QRegExp("^(?!ТЕСТ-М[^\\S*\\d*]).*$"); qDebug() << rx.indexIn("привет") << rx.indexIn("ТЕСТ-М60") << rx.indexIn("ТЕСТ-М"); 

At the exit, I get 0 0 0 , respectively, all three words matched. However, this pattern should not match the third word. And, for example, this does not happen here: regexstorm

Can I somehow not correctly set the pattern in Qt?

  • Maybe you need QRegExp("^(?!ТЕСТ-М(?:\\s|$)).*$") ? Shouldn't a string start with ТЕСТ-М followed by a whitespace or the end of a string? - Wiktor Stribiżew
  • [^\\S*\\d*] - this is - garbage. - Qwertiy

1 answer 1

I don’t know about QRegExp and cannot check it now, but for other components of Qt, specifically, QMap was faced with the fact that in the case of a request with a key that did not return the default value and also insert the structure itself, I had to wrap the call in if (map.contains("id")) { value = map["id"].toString()} . Perhaps the same behavior is there and you first need to make sure that the pattern is generally present in the string using exactMatch and only then look for it in the string