当我在 golang 中尝试这个正则表达式时,我遇到了正则表达式解析错误。
error parsing regexp: invalid or unsupported Perl syntax:
(?!
regexp.MustCompile("^(?!On.*On\\s.+?wrote:)(On\\s(.+?)wrote:)$"),
有人可以告诉我为什么它不起作用并帮助我解决这个问题吗?
谢谢
最佳答案
Go 正则表达式不支持环视。
作为解决方法,您可以使用
regexp.MustCompile(`^On\s(.+?)wrote:$`)
和
regexp.MustCompile(`^On.*On\s.+?wrote:`)
并检查第一个是否匹配字符串而第二个不匹配。
您还可以添加一个可选的捕获组 (.*On)?
regexp.MustCompile(`^On(.*On)?\s.+?wrote:`)
并检查是否存在匹配项,如果第 1 组以 On
结束,则返回 true - 如果是,则返回 false,否则 < em>是的。
关于regex - 错误解析正则表达式 : invalid or unsupported Perl syntax: `(?!` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38933898/