[英]Regular expression to accept only greek characters
I have this regular expression ^[A-Za-z]{2,3}[0-9]{3,4}$
with which I validate in an input field so that it has 2 or 3 letters and 3 or 4 numbers 我有这个正则表达式
^[A-Za-z]{2,3}[0-9]{3,4}$
,可以在输入字段中对其进行验证,使其具有2或3个字母和3或4个数字
I want to accept only greek characters. 我只想接受希腊字符。
I tried this ^[α-ωΑ-Ω]{2,3}[0-9]{3,4}$
from PHP and regexp to accept only Greek characters in form but with no luck 我尝试过PHP和regexp的
^[α-ωΑ-Ω]{2,3}[0-9]{3,4}$
, 只接受希腊字符的形式但没有运气
i also tried ^[\\p{Greek}]{2,3}[0-9]{3,4}$
but again no luck 我也尝试过
^[\\p{Greek}]{2,3}[0-9]{3,4}$
但还是没有运气
Any suggestions? 有什么建议么?
VALID STRINGS: ΚΚΞ542 OOP8888 ΠΠ8965 INVALID STRINGS: 555555 K879 ΓΗΥΟ565 无效的字符串:ΚΚΞ542OOP8888ΠΠ8965无效的字符串:555555 K879ΓΗΥ565
You may match chars with \\p{Greek}
and you must use the /u
modifier: 您可以将字符与
\\p{Greek}
匹配,并且必须使用/u
修饰符:
'~^\p{Greek}{2,3}[0-9]{3,4}$~u'
See the regex demo . 参见regex演示 。
Pattern details 图案细节
^
- start of string ^
-字符串开头 \\p{Greek}{2,3}
- 2 or 3 Greek chars \\p{Greek}{2,3}
-2或3个希腊字符 [0-9]{3,4}
- 3 or 4 ASCII digits [0-9]{3,4}
-3或4个ASCII数字 $
- end of string. $
-字符串结尾。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.