QRegExp use find forward slash(/) and backward slash(\)
General and Desktop
4
Posts
3
Posters
5.6k
Views
1
Watching
-
wrote on 9 May 2012, 04:03 last edited by
Hi
I am using QRegExp for file path. I have 2 type of file path.
- c:\Test\test.txt
- D:/Test/test.txt
i use QRegExp for first type. like @QRegExp rx("([a-z A-Z]:\\|\\\\)"); @
how to write QRegExp for forward slash(/) file path?
Regards,
M.Mathivanan -
wrote on 9 May 2012, 06:23 last edited by
I never tried, but I guess escaping will do the trick @/@
-
wrote on 9 May 2012, 08:20 last edited by
I tried not find the forward slash(/)
-
wrote on 9 May 2012, 09:11 last edited by
the forward slash / has no special meaning in regular expressions.
@QRegExp rx("([a-zA-Z]:[\\/]|[\\/]{2})");@
works for both backward and forward slashes. (Note I've removed the whitespace character from the drive letter)But beware, you should also allow unix paths like "/home/dermanu", so possibly group "[a-zA-Z]:" together and make it optional by appending a "?" character
1/4