QRegExp use find forward slash(/) and backward slash(\)
-
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 -
I never tried, but I guess escaping will do the trick @/@
-
I tried not find the forward slash(/)
-
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