如何使用正则表达式替换<li>anything</li>
中的“i”
代码:
var code = "<li>anything</li>"; // i don't know what is in <li>......</li>
结果应为:
var code = "<li>anyth1ng</li>"; // i don't know what is in <li>......</li>
答案 0 :(得分:6)
根据您提供给我们的信息,这些信息应该有效:
code = code.replace(/hi/g, "he");
code = code.replace(/i\</g, "e<");
如果您有更多要求,请更新问题以进行描述。
<强>更新强>
var code = "<li>hi ho hi ho it's off to work we go</li>";
code = code.replace(/\>.*\</g, function(m) {
return m.replace(/i/g, "e");
});