[英]Regex to match ASCII non-alphanumeric characters
I need a regex to match ASCII non-alphanumeric characters. 我需要一个正则表达式来匹配ASCII非字母数字字符。 The regex should not match non-ASCII characters.
正则表达式不应与非ASCII字符匹配。 I am using the following:
我使用以下内容:
"[\\u0000-\\u002f\\u003a-\\u0040\\u005b-\\u0060\\u007b-\\u007f]"
Can I simplify this regex ? 我可以简化这个正则表达式吗?
Yes you can use a character class intersection. 是的,您可以使用字符类交集。 Example:
例:
[\\p{ASCII}&&\\P{Alnum}]
This means: intersection between all ascii characters and all non alphanumeric characters 这意味着:所有ascii字符和所有非字母数字字符之间的交集
You can use this regex in Java 您可以在Java中使用此正则表达式
^(?=[^0-9a-zA-Z]+$)\p{ASCII}+$
OR else: 要不然:
^(?!\p{Alnum}+$)\p{ASCII}+$
You can use a set intersection: 您可以使用集合交集:
"[\\p{ASCII}&&[^\\p{Alnum}]]"
Read: Reference - What does this regex mean? 阅读: 参考 - 这个正则表达式是什么意思?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.