user53885
user53885

Reputation: 3829

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

I have a document that I'm parsing text out of - I'm trying to figure out how to use this RegEx expression 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!

Upvotes: 0

Views: 1880

Answers (1)

kennytm
kennytm

Reputation: 523294

Just put all those exceptional cases into the character class.

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

Upvotes: 4

Related Questions