开发者

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 \\\-~!@#$%^*()_+{}:|""?`;',./[\]]+");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜