PDA

View Full Version : QRegExp validate windows file path



niol1000
27th January 2010, 11:29
Hi all,

I'm trying to use QRegExp to validate a windows file path and I tried a lot of different regular expressions and I cant get it to work, this expression works in a lot of test tools but not in qt:

QRegExp uri("([a-z A-Z]:\\[^/:\*\?<>\|]+\.\w{2,6})|(\\{2}[^/:\*\?<>\|]+\.\w{2,6})");

Does someone has a working regexp or can you see whats the problem with the above.

Thanks for your help

/Nick

boudie
27th January 2010, 12:04
RegExp's are not really my piece of cake... But Qt works always with '/' as a separator, so maybe you have to change your backslashes into slashes?
.

franz
30th January 2010, 15:06
QRegExp is made to work with user input regular expressions. If you want to match a backslash, you have to use four in your code; two for the escape backslash and two for the actual backslash. That also goes for other escaped characters (e.g. \\b, \\s).

Review the QRegExp docs for more detailed info.