Need help with regular expression checking file path

I am using RegularExpressionValidator in visual studio and I am struggling to create the correct regular expression for my needs. Here is what I want:

An input can contain any character except <>:"/|?* In addition, an input cannot contain two backslashes in a string

So, it your\momwill be fine, but your\\momwill fail, as wellyour*mom

The closest I came to this question is something like

^(?=.*[^<>:"/|?*])(?:[^\\]+|\\(?:$|[^\\])).{0,100}$

but that will not work.

+3
source share
1 answer
^(?!.*\\\\)[^<>:"/|?*]*$

must do it.

(?!.*\\\\) states that there are no two backslashes in a string in a string.

[^<>:"/|?*]* matches any number of characters except characters inside the character class.

, Visual Studio ( IDE), .

+1

All Articles