Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't escape double quotes in RegularExpression using named parameters. C#

I have the following RegEx:

[RegularExpression(@"^[^,']+$|^$", ErrorMessageResourceName = "AlphaNumeric", ErrorMessageResourceType = typeof(Resources.LocalizedStrings))]

This currently allows all characters except a , and a '. However I also need to exclude " but so far have not been able to, as it ends the initial double quote after the @ sign. I've searched Google for help but none of the answers seem to relate to what I'm doing, or seem to work for me.

Can anyone point me in the right direction?

EDIT - Thanks to everyone for their help, using the unicode equivalent worked for me. \u0022 See Anirudh's answer

like image 511
user2248441 Avatar asked Oct 09 '13 14:10

user2248441


1 Answers

You need to escape "

With verbatim string's you need to escape " as ""

If that doesn't work use \u0022 which is unicode equivalent of " i.e @"^[^,'\u0022]+$|^$"

like image 69
Anirudha Avatar answered Oct 02 '22 14:10

Anirudha