regexregular-language

Regular expression for [a-zA-Z]


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

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


Solution

  • 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...).

    In Java, you can use \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.