您现在的位置是:首页 > 电脑技术查询 > web开发

用正則表達式能不能把字符串的所有的字母a b c de後面加1解决方案

编辑:chaxungu时间:2022-10-02 23:22:36分类:web开发

用正則表達式能不能把字符串的所有的字母a b c de後面加1
key= "a b c de ";//這是變量
key= "/[ " +key.replace(/[ ]/g, "| ") + "]/g ";
a=a.replace(key,怎麼寫);
用一句話能完成嗎?
後面那個替換怎麼寫?
其中key是變量。


------解决方案--------------------
?
var str= "a b c de3333333a b c de4444444444 ";
var key=/(a|b|c|de)/g;
alert(str.replace(key, "a2$1b1 "))