美文网首页
js replace

js replace

作者: EcoRI | 来源:发表于2018-12-01 20:55 被阅读0次

replace的第二个参数可以传入函数

var t="<ul><li>${name}a</li><li>${age}</li></ul>";

var bbb = t.replace(/\$\{([a-z]+)\}(a)/g,function(){ console.log(arguments) })

输出:

["${name}a",    // 匹配到的字符串

"name",    // 匹配的子字符串

"a",    // 匹配的子字符串

8,    // 匹配到的字符串在字符串中的位置

"<ul><li>${name}a</li><li>${age}</li></ul>"]    // 原始字符串

相关文章

网友评论

      本文标题:js replace

      本文链接:https://www.haomeiwen.com/subject/veorcqtx.html