doudao8283 2016-02-03 08:56
浏览 506
已采纳

在Go正则表达式中转义括号

I am tying to run the following regular expression on a string in Go

\(([0-9]+),([0-9.]+),(?:$([0-9]+))\)

but I keep getting the error unknown escape sequence: (

the string that I'm running it on is (1,53.38,$45) (2,88.62,$98) (3,78.48,$3) (4,72.30,$76) (5,30.18,$9) (6,46.34,$48)

So my question is, how do you escape parentheses in Go's regexp?

  • 写回答

1条回答 默认 最新

  • douwudie8060 2016-02-03 09:00
    关注

    You need to escape the backslashes, because \( isn't a valid excape sequence.

    "\\(([0-9]+),([0-9.]+),(?:$([0-9]+))\\)"
    

    More commonly you would use backticks for string literals without escaping:

    `\(([0-9]+),([0-9.]+),(?:$([0-9]+))\)`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部