How to match Cyrillic characters with a regular ex

2019-01-03 16:49发布

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]

7条回答
Root(大扎)
2楼-- · 2019-01-03 17:18

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

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-03 17:23

If your regex flavour supports Unicode blocks, you can match Russian (Cyrillic) characters with:

[\p{IsCyrillic}]

Otherwise try:

[U+0400–U+04FF]

Explanation:

[\p{IsCyrillic}]

Options: Case insensitive; Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture

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] .

查看更多
该账号已被封号
4楼-- · 2019-01-03 17:28

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

查看更多
迷人小祖宗
5楼-- · 2019-01-03 17:30

this worked for me

[a-z\u0400-\u04FF]
查看更多
祖国的老花朵
6楼-- · 2019-01-03 17:37

If you use modern PHP version - just:

preg_match("/^[\p{L}]+$/u");

Don't forget the u flag for unicode support!

查看更多
看我几分像从前
7楼-- · 2019-01-03 17:37

Regex to match cyrillic alphabets with normal(english) alphabets :

^[A-Za-z.!@?#"$%&:;() *\+,\/;\-=[\\\]\^_{|}<>\u0400-\u04FF]*$

It matches special chars,cyrillic alphabets,english alphabets.

查看更多
登录 后发表回答