Negative look-ahead in Go regular expressions

前端 未结 3 1669
日久生厌
日久生厌 2020-12-03 09:54

I\'m trying to use negative look-aheads in Go.

The following regular expression: BBB(((?!BBB).)*)EEE

http://rubular.com/r/Zw1vopp1MF

Howeve

3条回答
  •  伪装坚强ぢ
    2020-12-03 10:37

    dlclark/regexp2 is a port of the .NET framework's System.Text.RegularExpressions.Regex engine.

    There are some fundamental differences between .NET strings and Go strings that required a bit of borrowing from the Go framework regex engine as well. I cleaned up a couple of the dirtier bits during the port (regexcharclass.cs was terrible), but the parse tree, code emmitted, and therefore patterns matched should be identical.

    It's name dropped at the end of the lengthy discussion about O(n) regular expressions, and is caveated:

    However, I would advise caution as there are benefits to the re2-based engine that are not provided by more full featured engines with lookarounds. If you have the option then stick with the stdlib.

    The cost of features is a slower implementation.

提交回复
热议问题