javascript 阿拉伯语的正则表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11323596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Regular Expression For Arabic Language
提问by KF2
I want to write a regular expression that matches each word in a sentence:
我想写一个正则表达式来匹配句子中的每个单词:
My regular expression:"\b(\w+)\b
"
我的正则表达式:" \b(\w+)\b
"
Result:
结果:
While it works well with English Words. It does not work when using Arabic words. How could I accomplish the same feat for Arabic words?
虽然它适用于英语单词。使用阿拉伯语单词时不起作用。我怎么能在阿拉伯语单词上完成同样的壮举?
回答by Siva Charan
Try this:-
试试这个:-
function HasArabicCharacters(text)
{
var arregex = /[\u0600-\u06FF]/;
alert(arregex.test(text));
}
Arabic character set of list
列表的阿拉伯字符集
[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufc3f]|[\ufe70-\ufefc]
Arabic script in Unicode:
Unicode 中的阿拉伯文字:
As of Unicode 6.1, the Arabic script is contained in the following blocks:
从Unicode 6.1 开始,阿拉伯文字包含在以下块中:
Arabic (0600—06FF, 225 characters)
Arabic Supplement (0750—077F, 48 characters)
Arabic Extended-A (08A0—08FF, 39 characters)
Arabic Presentation Forms-A (FB50—FDFF, 608 characters)
Arabic Presentation Forms-B (FE70—FEFF, 140 characters)
Rumi Numeral Symbols (10E60—10E7F, 31 characters)
Arabic Mathematical Alphabetic Symbols (1EE00—1EEFF, 143 characters)
Contents are taken from wikipedia - Arabic script in Unicode
内容取自维基百科 - Unicode 中的阿拉伯文字
回答by vahidreza
I'd suggest this :
我建议这样做:
\p{InArabic}
回答by Monir Ahmad
You can do it with function to translate Aracbic Characters list, Its very simple to do.
您可以使用翻译阿拉伯语字符列表的功能来做到这一点,它非常简单。
As Like :
就像:
function (regexStr) {
regexStr = replace(regexStr,"?","\u0600");
regexStr = replace(regexStr,"?","\u06FF");
return regexStr;
}
Or in another idea replacing [alf] and [ya] to see your text direction correctly
或者在另一个想法中替换 [alf] 和 [ya] 以正确查看您的文本方向
var regexStr = "/[[alf]-[ya]]/";
function (regexStr) {
regexStr = replace(regexStr,"[alf]","\u0600");
regexStr = replace(regexStr,"[ya]","\u06FF");
return regexStr;
}