5

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.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
bn12
  • 75
  • 1
  • 5
  • 1
    Why can't you use `[a-zA-Z]`? – Zereges May 07 '15 at 20:20
  • [\[\[:alpha:\]\]](https://regex101.com/r/vD8yQ0/1) – dawg May 07 '15 at 20:49
  • I will explain my question abd i will ask you to forgive my terrible English. I am building an engine to recognize regular expressions in assembly (8086) for school project. And i want to know if there is any shortcut for the only the letters a-z and A-Z with no other letters. – bn12 May 08 '15 at 07:19

1 Answers1

6

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.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563