[英]Words with letter and numbers that can contain dashes and swedish characters
I would like to create a regexp which validates against all english letters + the swedish "åäö (lower and uppercase)". 我想创建一个正则表达式,以对所有英文字母+瑞典语“åäö(小写和大写)”进行验证。 Also, the word can contain 1 or more "-" and can be of any length.
同样,该单词可以包含1个或多个“-”,并且可以是任意长度。
^[a-zA-Z\\dåäöÅÄÖ\\-*]*$
Is this correct? 这个对吗? Can it be improved?
可以改善吗? If I recall correctly,
a-zA-Z
icludes more than just those letters (some characters in the ascii table between az and AZ). 如果我没记错的话,
a-zA-Z
不仅包含那些字母(az和AZ之间的ascii表中的某些字符)还包含更多内容。
http://regexr.com?36svf http://regexr.com?36svf
Update: Here are the characters that I'm refering to: 更新:这是我要指的字符:
Update 2: I also want to include digits. 更新2:我也想包含数字。
Your regex is OK, but why are you including the asterisk ( *
)? 您的正则表达式还可以,但是为什么要加上星号(
*
)?
[A-Za-z]
only matches ASCII letters, it's [Az]
that's problematic because there are some special characters between Z
and a
. [A-Za-z]
仅匹配ASCII字母,这是[Az]
的问题,因为Z
和a
之间有一些特殊字符。
So ^[a-zA-Z\\dåäöÅÄÖ-]*$
should be OK. 因此,
^[a-zA-Z\\dåäöÅÄÖ-]*$
应该可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.