UPDATE: There's more on Internationalized RegExs in this StackOverflow question.
更新:这个StackOverflow问题中有更多关于国际化RegEx的信息。
I was trying to make a regular expression for use in client-side JavaScript (using a PeterBlum Validator) that allowed a series of special characters:
我试图制作一个正则表达式以用于客户端JavaScript (使用PeterBlum Validator ),该表达式允许一系列特殊字符:
-'.,&#@:?!()$\/
-'。,&#@:?!()$ \ /
Plus letters and numbers and whitespace:
加上字母,数字和空格:
\w\d\s
\ w \ d \ s
However, I mistakenly assumed that \w meant truly "word characters." It doesn't, it means [A-Za-z].
但是,我错误地认为\ w的意思是真正的“单词字符”。 不是,意思是[A-Za-z]。
That sucks. What about José, when he wants to put his First Name into a form?
糟透了。 如果何塞想将其名字输入表格,该怎么办?
Well, I could do a RegEx that denies specific characters and allows all others, but I really just wanted to support Spanish, French, English, German, and any language that uses the general Latin Character Set.
好吧,我可以做一个RegEx来拒绝特定字符并允许所有其他字符,但是我真的只想支持西班牙语,法语,英语,德语以及使用常规拉丁字符集的任何语言。
So, here's what I have.
所以,这就是我所拥有的。
^[ ÀÈÌÒÙ àèìòù ÁÉÍÓÚ Ý áéíóúý ÂÊÎÔÛ âêîôû ÃÑÕ ãñõ ÄËÏÖÜŸ äëïöüŸ ¡¿çÇŒœ ßØøÅå ÆæÞþ Ðð ""\w\d\s-'.,&#@:?!()$\/]+$
^ [ÁÈÌÒÙàèìòùÁÉÍÓÚÝééóúýÊÎÔÛâêîôûÃÑÕõñõÄËÏÖÜŸäëïööŸ¡
Did I miss anything? (Ignore the whitespace for the purposes of this post's RegEx)
我有想念吗? (出于本文的RegEx的目的,请忽略空格)
It's lame that \w doesn't work on the client-side based on your browser's locale. This makes it difficult for your RegExes to have parity between the client and server.
根据浏览器的语言环境,\ w在客户端不起作用是很遗憾的。 这使RegExes很难在客户端和服务器之间具有奇偶校验。
翻译自: https://www.hanselman.com/blog/internationalized-regular-expressions