3

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

The input can contain any character except <>:"/|?* Also, the input can not contain two backslashes in a row

So, your\mom would be ok but your\\mom would fail as would your*mom

The closest I have come at this point is something like

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

but it doesn't work.

2
  • Does it have to be a regex? What about using the substring function to check that 1. none of <>:"/|?* is a substring of the input and 2. \\ is not a substring of the input? Commented May 19, 2011 at 19:39
  • Well, I suppose I could have used a custom validator and coded it to do that but the solution below works great so I'm gonna call it good Commented May 20, 2011 at 18:39

1 Answer 1

1
^(?!.*\\\\)[^<>:"/|?*]*$

should do it.

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

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

That is, unless you're talking about the regex features of Visual Studio (the IDE environment itself) which has a wildly nonstandard regex flavor.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.