开发者

.Net Regex that Matches Strings With Any non-ASCII char in it

开发者 https://www.devze.com 2023-01-12 19:03 出处:网络
Looking for some black magic that will match any string with \"weird\" characters in it. Standard ASCII characters are fine. Everything else isn\'t.

Looking for some black magic that will match any string with "weird" characters in it. Standard ASCII characters are fine. Everything else isn't.

This is for sanitizing 开发者_运维知识库various web forms.


This gets anything out of the ASCII range

[^\x00-\x7F]

There are still some "weird" characters like x00 (NULL), but they are valid ASCII.
For reference, see the ASCII table


[^\p{IsBasicLatin}] for what is asked for, [^\x00-\x7F] for concision over self-documentation, or \p{C} for clearing out formatters and controls without hurting other non-ASCIIs (and with greater concision yet).

0

精彩评论

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