[a-zA-Z]的正则表达式

时间:2022-01-16 16:51:34

I have a regular expression that matches English letters only, a [a-zA-Z] character class.

我有一个只与英文字母匹配的正则表达式,一个[a-zA-Z]字符类。

Is there any built-in regular expression for that? I mean something like \s or \w.

有没有内置的正则表达式?我的意思是像\ s或\ w。

1 个解决方案

#1


You are asking for a shorthand class for English letters.

你正在要求英文字母的速记课程。

In case you are using POSIX-compliant regex, [:alpha:] is the "bracket expression" for [a-zA-Z] class. It is also supported by PCRE (Perl, PHP, Ruby...).

如果您使用符合POSIX的正则表达式,[:alpha:]是[a-zA-Z]类的“括号表达式”。它也受到PCRE(Perl,PHP,Ruby ......)的支持。

In Java, you can use \p{Alpha}.

在Java中,您可以使用\ p {Alpha}。

In .NET, PCRE, Java, \p{L} is more than just [a-zA-Z] as it might include all Unicode letters. Still, it can be used to capture only letters.

在.NET,PCRE,Java中,\ p {L}不仅仅是[a-zA-Z],因为它可能包含所有Unicode字母。不过,它只能用于捕捉字母。

#1


You are asking for a shorthand class for English letters.

你正在要求英文字母的速记课程。

In case you are using POSIX-compliant regex, [:alpha:] is the "bracket expression" for [a-zA-Z] class. It is also supported by PCRE (Perl, PHP, Ruby...).

如果您使用符合POSIX的正则表达式,[:alpha:]是[a-zA-Z]类的“括号表达式”。它也受到PCRE(Perl,PHP,Ruby ......)的支持。

In Java, you can use \p{Alpha}.

在Java中,您可以使用\ p {Alpha}。

In .NET, PCRE, Java, \p{L} is more than just [a-zA-Z] as it might include all Unicode letters. Still, it can be used to capture only letters.

在.NET,PCRE,Java中,\ p {L}不仅仅是[a-zA-Z],因为它可能包含所有Unicode字母。不过,它只能用于捕捉字母。