Regex to match only letters

我如何写一个只匹配字母的正则表达式?


Use a character set: [a-zA-Z] matches one letter from A–Z in lowercase and uppercase. [a-zA-Z]+ matches one or more letters and ^[a-zA-Z]+$ matches only strings that consist of one or more letters only ( ^ and $ mark the begin and end of a string respectively).

If you want to match other letters than A–Z, you can either add them to the character set: [a-zA-ZäöüßÄÖÜ] . Or you use predefined character classes like the Unicode character property class p{L} that describes the Unicode characters that are letters.


如果您对超出拉丁字母的字母感兴趣, p{L}匹配任何一个Unicode字母


Depending on your meaning of "character":

[A-Za-z] - all letters (uppercase and lowercase)

[^0-9] - all non-digit characters

链接地址: http://www.djcxy.com/p/76890.html

上一篇: 正则表达式:删除包含的行

下一篇: 正则表达式只匹配字母