【问题标题】:Parenthesis not being replaced in regex正则表达式中没有替换括号
【发布时间】:2012-05-25 14:15:20
【问题描述】:

我知道网上有很多方法,但这种情况很特殊。

我需要将:) 替换为<img src="smiley.gif">。和

str.replace(/:)/g,'img src="smiley.gif"')

不工作!请帮帮我!

【问题讨论】:

  • 以后可以尝试调试此类问题,例如':'.replace(/:/, 'test')和')'.replace(/)/, 'test')
  • 是的,谢谢。只是我真的很累,而且我的想法不在正确的地方。

标签: javascript string replace


【解决方案1】:

你必须转义括号:

str.replace(/:\)/g, '<img src="smiley.gif">');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 2019-10-25
    相关资源
    最近更新 更多