RegEx扩展拉丁字母(äöüèß) [英] RegEx with extended latin alphabet (ä ö ü è ß)
问题描述
我想在Node.js中做一些基本的字符串测试。假设我有一个表单,用户输入他们的名字,我想检查它是垃圾还是真名。
I want to do some basic String testing in Node.js. Assume I have a form where users enter their name and I wanna check if it's just rubbish or a real name.
幸福(或者我的支票很遗憾)我从中获取用户在世界各地,这意味着他们的名字包含非英文字符,如äöüßé
。我习惯使用 / [A-Za-z - ] {2,} /
,但这与JanBuschtöns之类的名称不匹配
。
Happily (or sadly for my check) I get users from all around the world which means that their names contain non-english characters, like ä ö ü ß é
. I was used to use /[A-Za-z -]{2,}/
but this doesn't match names like "Jan Buschtöns"
.
我是否必须手动将每个可能的非英语但拉丁字符添加到我的RegEx才能工作?我不想要一个100多个字符长的RegEx,如 / [A-Za-z-äöüÄÖÜßéÉèÈêÊ...] {2,} /
。
Do I have to manually add every possible non-english but latin character to my RegEx to work? I don't want a 100+ characters long RegEx like /[A-Za-z -äöüÄÖÜßéÉèÈêÊ...]{2,}/
.
推荐答案
检查 http:/ /www.regular-expressions.info/unicode.html 和 http://xregexp.com/plugins/
如果你想要,你需要使用 \p {L}
来匹配任何字母字符包含unicode。
You would need to use \p{L}
to match any letter character if you want to include unicode.
说到unicode,替代 \w
是 [\ p {L} \p {N} _]
然后。
Speaking unicode, alternative of \w
is [\p{L}\p{N}_]
then.
这篇关于RegEx扩展拉丁字母(äöüèß)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!