Javascript 搜索和替换unicode字符

Javascript 搜索和替换unicode字符,javascript,jquery,regex,unicode,Javascript,Jquery,Regex,Unicode,我正在使用这个jQuery脚本。 我试图将每个字符都放在一个范围内,但它不适用于unicode字符 $("body").children().andSelf().contents().each(function(){ if (this.nodeType == 3) { var $this = $(this); $this.replaceWith($this.text().replace(/(\w)/g, "<span>$&</sp

我正在使用这个jQuery脚本。 我试图将每个字符都放在一个范围内,但它不适用于unicode字符

$("body").children().andSelf().contents().each(function(){
    if (this.nodeType == 3) {
        var $this = $(this);
        $this.replaceWith($this.text().replace(/(\w)/g, "<span>$&</span>"));
    }
});
$(“body”).children()和self().contents().each(function()){
if(this.nodeType==3){
var$this=$(this);
$this.replaceWith($this.text().replace(/(\w)/g,“$&”);
}
});
我应该更改节点类型吗?凭什么

谢谢

将\w(仅单词字符)替换为“.”(所有字符)

$(“body”).children()和self().contents().each(function()){
if(this.nodeType==3){
var$this=$(this);
$this.replaceWith($this.text().replace(/()/g,“$&”);
}
})
将\w(仅单词字符)替换为“.”(所有字符)

$(“body”).children()和self().contents().each(function()){
if(this.nodeType==3){
var$this=$(this);
$this.replaceWith($this.text().replace(/()/g,“$&”);
}
})

匹配“任意字符”的正则表达式模式是
而不是
\w
(它只匹配“单词字符”-在大多数JS风格中是字母数字字符和下划线
[a-zA-Z0-9\]
)。注意
也匹配空格字符。要仅匹配和替换非空格字符,可以使用
\S

有关JS正则表达式语法的完整列表,请参阅

要替换任何和所有字符,请使用正则表达式
//g

$("body").children().andSelf().contents().each(function(){
    if (this.nodeType == 3) {
        var $this = $(this);
        $this.replaceWith($this.text().replace(/(.)/g, "<span>$&</span>"));
    }
});
$(“body”).children()和self().contents().each(function()){
if(this.nodeType==3){
var$this=$(this);
$this.replaceWith($this.text().replace(/()/g,“$&”);
}
});

匹配“任意字符”的正则表达式模式是
而不是
\w
(它只匹配“单词字符”-在大多数JS风格中是字母数字字符和下划线
[a-zA-Z0-9\]
)。注意
也匹配空格字符。要仅匹配和替换非空格字符,可以使用
\S

有关JS正则表达式语法的完整列表,请参阅

要替换任何和所有字符,请使用正则表达式
//g

$("body").children().andSelf().contents().each(function(){
    if (this.nodeType == 3) {
        var $this = $(this);
        $this.replaceWith($this.text().replace(/(.)/g, "<span>$&</span>"));
    }
});
$(“body”).children()和self().contents().each(function()){
if(this.nodeType==3){
var$this=$(this);
$this.replaceWith($this.text().replace(/()/g,“$&”);
}
});

您所说的“unicode字符”是什么意思?(注意:从jQuery 1.8版开始。您应该改为使用,这是等效的,但我想他们更喜欢这个名称。)“unicode字符”是什么意思?(注意:从jQuery 1.8版开始,您应该改为使用,这是等效的,但我想他们更喜欢这个名称。)这将是可怕的失败,这将是可怕的失败