dongxia9519
2016-08-13 14:50
浏览 1.6k
已采纳

解析regexp时出错:Perl语法无效或不受支持:`(?!

When I try this regex in golang I'm getting regex parsing error.

error parsing regexp: invalid or unsupported Perl syntax: (?!

regexp.MustCompile("^(?!On.*On\\s.+?wrote:)(On\\s(.+?)wrote:)$"),

Can someone tell me why its not working and help me to fix this issue?

Thanks

图片转代码服务由CSDN问答提供 功能建议

当我在golang中尝试此正则表达式时,出现正则表达式解析错误。

错误解析正则表达式:无效或不受支持的Perl语法:(?! <预> <代码> regexp.MustCompile( “^(?亮*亮\\ S +写道:。?)(在\\ S(+)中写道:?)$”),

有人可以告诉我为什么它不起作用并帮助我解决此问题吗?

谢谢

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dssnh86244 2016-08-13 16:58
    已采纳

    Go regex does not support lookarounds.

    As a workaround, you may use

    regexp.MustCompile("^On\\s(.+?)wrote:$")
    

    and

    regexp.MustCompile("^On.*On\\s.+?wrote:")
    

    and check if the first one matches the string and the second does not.

    You could also add an optional capturing group (.*On)?

    regexp.MustCompile("^On(.*On)?\\s.+?wrote:")
    

    and check if there is a match and return true if the Group 1 ends with On - if yes, return false, else true.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题