Mark Richman
Mark Richman

Reputation: 29720

Regex to remove non-URL friendly characters, but allow Unicode and accents

I have the following regex:

foo = Regex.Replace(foo, @"[^a-zA-Z0-9\s-]", " ");

Currently, this removes Unicode characters. What regex can I use remove all non-URL friendly characters (i.e. : , < etc.), but allow Unicode and accented characters?

Thanks, Mark

Upvotes: 0

Views: 2353

Answers (2)

Mark Richman
Mark Richman

Reputation: 29720

Microsoft.Security.Application.AntiXss.GetSafeHtml() solved my problem.

Upvotes: 0

Razor Storm
Razor Storm

Reputation: 12336

How about instead of using a negated class, you simply have a replacement list of the characters you dont want?

s/[:,<]*//g

Upvotes: 3

Related Questions