【发布时间】:2023-03-26 16:53:02
【问题描述】:
我一直在为这个问题苦苦挣扎,代码在拉丁字符上运行良好,至于西里尔文,jquery 根本无法识别它。
$('p').each(function() { var $this = $(this);
$this.html($this.text().replace(/\b(\w+)\b/g, "<span>$1</span>"));
});
我也尝试过下面的代码,但是由于某种原因,jQuery 会跳过每个第二个单词并且不换行 :(
$(this).html($(this).text().replace(/\s([a-zA-Zа-яА-ЯёЁ]+)\s/g, " <span> $1 </span> "));
有什么提示吗?
【问题讨论】:
标签: javascript jquery regex replace cyrillic