I have been doing some searching for a regex that can be used as a rule to disallow users entering windows file paths without escaping the “\”. So far I have found this expression
[^\\]*$
However, this fails for the following:
C:\\Program Files\\testing
By fails I mean that it does not validate this string. Any help would be greatly appreciated, and yes I am bound to using regex.
will match strings that only contain escaped
\characters or non-\characters. (For a little extra performance, you could improve it to:^(?:\\\\|[^\\]+)*$)In Perl:
This will match
and fail
etc.