如果我有以下html:
<p>e: 1-800-hello-49</p>
<p>another line</p>
<p>
f: 1-800-hello-49
g: 1-800-hello-49
</p>
我希望能够在行首检测到一个字符,然后检测到一个冒号,以便获得以下输出:
<p><span>e:</span> 1-800-hello-49</p>
<p>another line</p>
<p>
<span>f:</span> 1-800-hello-49
<span>g:</span> 1-800-hello-49
</p>
我尝试过使用正则表达式,但是在这种情况下我很难掌握正则表达式。
尝试
$('p').html(function(idx, html){
return html.replace(/\b([a-z]:)/ig, '<span>$1</span>')
})
演示:小提琴
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句