Important: Please read the Qt Code of Conduct -

QRegExp use find forward slash(/) and backward slash(\)

  • Hi

    I am using QRegExp for file path. I have 2 type of file path.

    1. c:\Test\test.txt
    2. 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?


  • 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

Log in to reply