美文网首页
Golang 正则限制

Golang 正则限制

作者: 戈壁堂 | 来源:发表于2020-08-04 20:06 被阅读0次

    https://groups.google.com/forum/#!topic/golang-nuts/7qgSDWPIh_E

    that (?!re) regular expression is not supported neither in re2 nor in Google Go. Is there any chance that its support will be implemented in future releases? (it is supported at least in Ruby, Python, Java, Perl)

    https://www.reddit.com/r/programmingcirclejerk/comments/5ml6yj/golangs_standard_regex_library_doesnt_have/

    go-issues:18868 regexp: support lookaheads and lookbehinds

    Golang doesn't support positive lookbehind assertion?

    支持的场景: https://github.com/google/re2/wiki/Syntax要求makes a single scan over the input and runs in O(n) time

    The lack of generalized assertions, like the lack of backreferences, is not a statement on our part about regular expression style. It is a consequence of not knowing how to implement them efficiently. If you can implement them while preserving the guarantees made by the current package regexp, namely that it makes a single scan over the input and runs in O(n) time, then I would be happy to review and approve that CL. However, I have pondered how to do this for five years, off and on, and gotten nowhere.

    包含在一传字符串中的手机号,类似abcd13566778888xyz这样的手机号码前后不包含数字的正则在Go语言里是不支持的。因为无法一次扫描并在O(n)的时间里完成。

    (?=re) before text matching re (NOT SUPPORTED)
    (?!re) before text not matching re (NOT SUPPORTED)
    (?<=re) after text matching re (NOT SUPPORTED)
    (?<!re) after text not matching re (NOT SUPPORTED)

    相关文章

      网友评论

          本文标题:Golang 正则限制

          本文链接:https://www.haomeiwen.com/subject/npxgrktx.html