Help with regular expression

utilitaire

Regular
Joined
May 4, 2005
Messages
77
I have a question for you guys about a regular expression i want to build.

I have a string that i want to test. I have my pattern that should be 1 to X times in my string. Thats works.

But also, my customer can pass an empty value for this string. If my customer pass nothing, i want my regular expression to succeed also cause i accept empty value for certain textbox. I cant figure out how to manage an empty value in my string.

Hope someone can give me a hint on that.

Thanks in advance.
 
will the "*" (0 or more) operator work for you? or perhaps "^0" ? You can try oring using the pipe | to say "Either my regex or nothing". I think the ^ operator is what you seek, though.

Also, why not just do a check for empty string and then apply your regex?
if (value == "" || Regex.Matches(...)) {... }
 
Back
Top