开发者

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

开发者 https://www.devze.com 2023-03-08 02:16 出处:网络
I have the following regex: foo =开发者_高级运维 Regex.Replace(foo, @\"[^a-zA-Z0-9\\s-]\", \" \");

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


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

s/[:,<]*//g


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

0

精彩评论

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

关注公众号