括号没有在正则表达式中被替换 [英] Parenthesis not being replaced in regex
本文介绍了括号没有在正则表达式中被替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道互联网上有很多方法,但这种情况很特殊.
I know there are many ways over the internet but this case is a special one.
我需要用 <img src="smiley.gif">
替换 :)
.还有
I need to replace :)
with <img src="smiley.gif">
. And
str.replace(/:)/g,'img src="smiley.gif"')
不起作用!请帮帮我!
推荐答案
你必须转义括号:
str.replace(/:\)/g, '<img src="smiley.gif">');
这篇关于括号没有在正则表达式中被替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文