问题
How do I match French and Russian Cyrillic alphabet characters with a regular expression? I only want to do the alpha characters, no numbers or special characters. Right now I have
[A-Za-z]
回答1:
It depends on your regex flavor. If it supports Unicode character classes (like .NET, for instance), \p{L}
matches a letter character (in any character set).
回答2:
If your regex
flavor supports Unicode blocks ([\p{IsCyrillic}]
), you can match Russian (Cyrillic) characters with:
[\p{IsCyrillic}] or [\p{Cyrillic}]
Otherwise try using:
[U+0400–U+04FF]
For PHP
use:
[\x{0400}-\x{04FF}]
Explanation:
[\p{IsCyrillic}]
Match a character from the Unicode block “Cyrillic” (U+0400–U+04FF) «[\p{IsCyrillic}]»
Note:
Unicode Characters list and Numeric HTML Entities of [U+0400–U+04FF] .
回答3:
If you use modern PHP version - just:
preg_match("/^[\p{L}]+$/u");
Don't forget the u flag for unicode support!
回答4:
Regex to match cyrillic alphabets with normal(english) alphabets :
^[A-Za-z.!@?#"$%&:;() *\+,\/;\-=[\\\]\^_{|}<>\u0400-\u04FF]*$
It matches special chars,cyrillic alphabets,english alphabets.
回答5:
this worked for me
[a-z\u0400-\u04FF]
回答6:
Various regex dialects use [:alpha:]
for any alphanumeric character in the current locale. (You may need to put that in a character class, e.g. [[:alpha:]]
.)
回答7:
If you use Elixir:
String.match?(string, ~r/^\p{Cyrillic}*$/u)
You need to add the u
flag for unicode support.
回答8:
To match only Russian Cyrillic characters use:
[\u0401\u0451\u0410-\u044f]
which is the equivalent of:
[ЁёА-я]
where А
is Cyrillic, not Latin. (Despite looking the same they have different codes)
\p{IsCyrillic}
, \p{Cyrillic}
, [\u0400-\u04FF]
which others suggested will match all variants of Cyrillic, not only Russian
回答9:
In Java to match Cyrillic letters and space use the following pattern
^[\p{InCyrillic}\s]+$
来源:https://stackoverflow.com/questions/1716609/how-to-match-cyrillic-characters-with-a-regular-expression