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

JQuery/Javascript - Need RegEx to match the multilingual text

本文关键字:语言 文本 正则表达式 Javascript JQuery      更新时间:2023-09-26

我正在使用下面的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(");

我不知道不知何故,这一行与其他语言文本(英语除外)不匹配......