我需要一个不允许字符的正则表达式。
^[A-Z0-9 _]*[A-Z0-9][A-Z0-9 _]*$
这些似乎不起作用,因为我需要转义任何类型的字符(英语、中文、希腊语等)
If you only want to accept digits and the . character using POSIX (PHP):
^[.1-9]*$
If you want to explicit exclude word characters
^[^\w]*$
This will match anything but word characters.
Note (that as has been replied in the comments):
You edited your post and stated that you use PHP. As far as I know it uses POSIX ERE. In that case this solution will not work. However I keep my answer for the search functionality in case another user (that does use the supported engines) finds this answer.
使用\p{L}
或\p{Letter}
匹配任何语言的任何 (Unicode) 字母。要匹配任何非字母,您应该使用:\p{^L}
或\P{L}
(取决于您使用的正则表达式引擎)来否定。
任何字符 \w
不是字符 \W