Go中的不良正则表达式

huangapple go评论60阅读模式
英文:

Poor regular expressions in Go

问题

为什么Go语言中的regexp包不支持像样的正则表达式?例如,截至Go r60.3版本,字符类\w和\s尚未实现。此外,(?:non)非捕获组也无法识别。

英文:

Why does the regexp package in Go no support decent regexp? For example the character classes \w and \s are not implemented as of Go r60.3. Also (?:non) capturing groups are not recognized.

答案1

得分: 6

使用“现有技术状态”的正则表达式包
它支持\w\s,还可以处理非捕获组(?:re)

英文:

Use the "current state of art" regexp package.
It has support for \w and \s and also handles non capturing groups (?:re).

答案2

得分: 1

EDIT:忽略那个:我还没有看过最近版本的正则表达式包。

如果这真的是一个问题,我想我们可以回答目前还没有人花时间构建一个完整的正则表达式库。

如果你这样做,请不要忘记考虑到现代正则表达式需要在Unicode方面正确。说到你提到的\w,那并不简单:'é'是一个单词字符。不要移植像标准JavaScript正则表达式包这样的东西。

英文:

EDIT : disregard that : I hadn't had a look at the recent versions of the regexp package

If that's really a question, I suppose we could answer that nobody for now took the time to build a complete regexp library.

If you do so, don't forget to take into account that modern regexp need to be correct regarding Unicode. Speaking of the \w you mentionned, that's not so simple : 'é' is a word character. Don't port something like the standard javascript regexp packages.

答案3

得分: 0

文档中指出“Package regexp实现了一个简单的正则表达式库”,所以我猜现在拥有一个功能完整的正则表达式库并不是当务之急。

英文:

The documentation states that 'Package regexp implements a simple regular expression library' so I guess it's not a priority at the moment to have a fully featured regex library.

huangapple
  • 本文由 发表于 2012年3月13日 17:26:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/9681342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定