C# Regular Expression - Adding Special Characters
I was wonderi开发者_StackOverflow中文版ng what is the best way to include backslash and other special characters in a group?
example:
"message":"\"rock on\" \\,,/,[-_-]";
help me on my regex
[a-zA-Z0-9 \\-~!@#$%^*()_+{}:|?`;',\\./\\[\\]]+
Just escape those that need to be escaped and add those, that don't need to:
[a-zA-Z0-9 \\\-~!@#$%^*()_+{}:|"?`;',./[\]]+
To elaborate a bit:
You only need to escape \
, ]
and -
inside a character group.
Using C#, it would look like this:
Regex rx = new Regex(@"[a-zA-Z0-9 \\\-~!@#$%^*()_+{}:|""?`;',./[\]]+");
精彩评论