Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery/Javascript-需要正则表达式来匹配多语言文本_Javascript_Jquery_Regex - Fatal编程技术网

JQuery/Javascript-需要正则表达式来匹配多语言文本

JQuery/Javascript-需要正则表达式来匹配多语言文本,javascript,jquery,regex,Javascript,Jquery,Regex,我使用下面的jQuery代码搜索页面上的文本,但这不会搜索网页上的法语或其他语言文本。使用的jQuery代码如下所示- phrase = ["\\b(", phrase, ")"].join(""); //search for any matches var count = 0; $("#faq-container p").each( function (i, v) { //replace any matches var block = $(v);

我使用下面的jQuery代码搜索页面上的文本,但这不会搜索网页上的法语或其他语言文本。使用的jQuery代码如下所示-

phrase = ["\\b(", phrase, ")"].join("");

//search for any matches
var count = 0;
$("#faq-container p").each(
    function (i, v) {
        //replace any matches
        var block = $(v);
        block.html(
            block.text().replace(
                //new RegExp(phrase, "gi"), function (match) { // properties used g , i => g -> global : Whether to test the regular expression against all possible matches in a string, or only against the first.
                // i -> ignoreCase : Whether to ignore case while attempting a match in a string.
                phrase, function (match) {
                    count++;
                    return ["<span class='highlight'>", match, "</span>"].join("");
                }
            )
        );
    }
);

只需删除第行下方的一行即可解决此问题-

短语=[\b,短语,].join


我不知道怎么回事,这行代码与英语以外的其他语言文本不匹配……

这是一种不寻常的JavaScript编码风格!为什么您认为这是Javascript不寻常的编码风格?我需要这个代码来搜索网页上的文本并突出显示匹配的文本。-但是我看到它被编辑了。代码对我来说看起来缩进得很好…现在,在发布它的时候看起来像