donglei7152 2017-02-25 13:01
浏览 249
已采纳

如何在Windows上使用基于cgo的程序包?

The regexp in the Go's standard library is quite poor, so I need a more powerful engine, like regex in Python (pip install regex), supporting recursion, backref, look-ahead/behind, etc... .

I found: https://godoc.org/github.com/dlclark/regexp2 .NET compatible, which was quite fine; however, recursion is not working properly.

and several bindings to PCRE, for example: https://godoc.org/github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre

so, how can I use this binding on Win64?

  • 写回答

1条回答 默认 最新

  • dora12345678 2017-02-25 14:30
    关注

    You may consider using C++ standard library std::regex (no third-party library). Wrap the logic in try block, use catch(...){return ERROR;} to catch any error, and declare the C function extern "C" so you can call with cgo.


    From https://github.com/golang/go/wiki/cgo (there is a part about Windows):

    In order to use cgo on Windows, you'll also need to first install a gcc compiler (for instance, mingw-w64) and have gcc.exe (etc.) in your PATH environment variable before compiling with cgo will work.


    That being said, I still think you should consider sticking with the regexp package and try to make regular expressions as simple as possible. Because complicated regular expressions are likely to hurt readability of code. Another problem is sometimes they introduce subtle bugs which are difficult to spot and fix. So writing more code in Go instead of regex may actually make the life easier.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python验证码滑块图像识别
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)