小编Joh*_*ohn的帖子

用正则表达式拆分和替换javascript中的unicode单词

需要在{}中的unicode字符串中放置unicode单词列表.有我的代码:

var txt = "¿One;one oneé two two two two two twö twöu three;;twä;föur?";
var re = new RegExp("(^|\\W)(one|tw|two two|two|twöu|three|föur)(?=\\W|$)", "gi");
alert(txt.replace(re, '$1 {$2}'));
Run Code Online (Sandbox Code Playgroud)

它返回:

¿{One}; {one} {one}é{two two} {two two} {two} {tw}ö{tw}öu{three} ;; {tw}ä; {föur}?

但应该是:

¿{One}; {one}oneé{two two} {two two} {two}twö{twöu} {three} ;;twä; {föur}?

我做错了什么?

javascript regex unicode split

5
推荐指数
2
解决办法
2310
查看次数

标签 统计

javascript ×1

regex ×1

split ×1

unicode ×1