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

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

问题描述

我发现了这个阿拉伯字母的正则表达式,但它也允许带有字母的数字.我怎样才能改变它让它只允许字母?

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天全站免登陆