正则表达式不允许数字-只能是阿拉伯字母 [英] Regular Expression not to allow numbers - just Arabic letters

查看:428
本文介绍了正则表达式不允许数字-只能是阿拉伯字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个正则表达式是阿拉伯字母,但是它也允许带字母的数字.如何更改它以使其只允许字母?

I found this regular expression for Arabic letters but it is also allowing numbers with letters. How can I change it to let it allow letters only ?

/[\u0600-\u06FF]/

推荐答案

可能您需要检查数字匹配的范围并将其排除在外(正式不包括在方括号表达式中).

Probably you'd have to check what range the numbers match and exclude it (formally not include in brackets expression).

此处我找到了另一个有用的资源.

Here I've found another helpful source.

我建议只在字母中使用

/[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF]/

因为这仅匹配阿拉伯数字

as this matches arabic digits only

/[\u0660-\u0669\u06F0-\u06F9]/

我发现unicode中有两个阿拉伯数字和阿拉伯印度数字范围.

I've found that there are two ranges for arabic and arabic-indic digits in unicode.

如果您需要正则表达式来匹配一行,那么当它包含阿拉伯字母和数字时,请使用以下命令:

If you need a regex to match a line just then, when it contains arabic letters and numbers - use this:

/^[\u0600-\u06FF]*$/

如果您还不希望使用阿拉伯数字,请使用以下命令:

If you want to also discourage arabic digits - use this:

/^[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF]*$/

如果您想匹配一个子字符串,而不仅是整行,请使用以下命令:

If you want to match a substring, not only a whole line, use this:

/\b[\s\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF]*\b/

这篇关于正则表达式不允许数字-只能是阿拉伯字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆