开发者

How to strip out all characters except for numbers, letters, quotes, and colons/semi-colons?

开发者 https://www.devze.com 2022-12-28 15:57 出处:网络
I have a document that I\'m parsing text out of - I\'m trying to figure out how to use this RegEx exp开发者_开发问答ression to take out everything that isn\'t alphanumeric, but I want to keep quotes,

I have a document that I'm parsing text out of - I'm trying to figure out how to use this RegEx exp开发者_开发问答ression to take out everything that isn't alphanumeric, but I want to keep quotes, ampersands and colons/semi-colons.

               s = Regex.Replace(s, @"[^\w-]+", " ");

How can I add a replace all of these "except these" pattern here?

Thank you!


Just put all those exceptional cases into the character class.

s = Regex.Replace(s, @"[^\w'""&:;-]+", " ");
0

精彩评论

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