PDA

View Full Version : Negation of QregExp



MasterBLB
27th November 2012, 10:49
Hello all

I have a such working expression set on a line edit:

locationDirPathValidator.setRegExp(QRegExp("[?<>:*|\"]{0,}"));
it works well.
But the point is how to make a negation of such expression?I tried ^(?![?<>:*|\"])$ but it does not work :/
Could you help me?

ChrisW67
27th November 2012, 23:01
Your initial pattern matches a string consisting of zero or more characters from the list; ?, <, >, :, *, | and "
By my reckoning the inverse of that would be a non-zero length string that does not contain any of those characters:


locationDirPathValidator.setRegExp(QRegExp("[^?<>:*|\"]+"));

MasterBLB
28th November 2012, 07:46
Thanks a lot Chris,that's exactly I was needed.
But please explain me what that + does?I found nothing about it in the Qt Assistant

amleto
28th November 2012, 08:16
+ means 1 or more instances of the previous element.

Incidentally, it is shorter to use * than {0,} for zero or more ocurrences.

a* (match zero or more 'a')

ChrisW67
28th November 2012, 23:53
The +, *, and ? quantifiers are documented in the QRegExp (http://qt-project.org/doc/qt-4.8/QRegExp.html#quantifiers) documentation. These symbols are universal in regular expression engine implementations.