javascript匹配双花括号内的希伯来语单词
我有一个js函数,用英语工作,但我用希伯来语出错 该函数匹配javascript匹配双花括号内的希伯来语单词,javascript,regex,Javascript,Regex,我有一个js函数,用英语工作,但我用希伯来语出错 该函数匹配{}中字符串中的所有单词,并返回数组中双花括号内的单词(不带花括号) 字符串可以包含以下英语和非英语单词:{{test}{{{1489; 1497;קה}}hi this is my test{{test2} var str_eng = "{{test}} {{test1}}"; var str_non_eng = "{{בדיקה}} {{עעע}}"; str_eng.match(/{{\s*[\w\.]+\s*}}/g).ma
{}
中字符串中的所有单词,并返回数组中双花括号内的单词(不带花括号)
字符串可以包含以下英语和非英语单词:{{test}{{{1489; 1497;קה}}hi this is my test{{test2}
var str_eng = "{{test}} {{test1}}";
var str_non_eng = "{{בדיקה}} {{עעע}}";
str_eng.match(/{{\s*[\w\.]+\s*}}/g).map(function(x) { return x.match(/[\w\.]+/)[0]; }) //array[ "test","test1" ] //ok
str_non_eng.match(/{{\s*[\w\.]+\s*}}/g).map(function(x) { return x.match(/[\w\.]+/)[0]; }) // error not working
谢谢 \w
与希伯来文字符不匹配-为此,您需要在希伯来文的Unicode范围内与[\u0590-\u05FF]
匹配-请参阅
您可以混合\w
和[\u0590-\u05FF]
以匹配ASCII和希伯来语:
//var str_non_eng=“{{1489;דיקה}{{{1506;עע}”;
var str_non_eng=“{{test}{{{1489;יקה}}这是我的测试{{test2}”;
变量r1=/{{\s*[\w\u0590-\u05FF\.]+\s*}}/g
变量r2=/[\w\u0590-\u05FF\.]+/;
var foo=str_non_eng.match(r1).map(函数(x){
返回x.match(r2)[0];
});
console.log(foo)代码>希伯来文字符不能使用\w。
使用以下命令:
/{{\s*[\w\u0590-\u05FF\.]+\s*}}/g
将第一位中的[\w\.]+
替换为*?
,只需通过映射中的substr()
移除括号即可。可以重复@NiettheDarkAbsol吗?您能告诉我如何操作吗?谢谢如果我的字符串不包含{{}我得到错误,“test test”如果你的字符串没有{{}
,那么你会把代码分成两部分-var foo=str_non_eng.match(r1)
thenif(foo){//do the rest}
if(str.indexOf(“}”)!=-1;{return str}
为我修复了它