Does go regexp's any charcter match newline

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

Does go regexp's any charcter match newline

问题

Go的re2语法文档中说,任意字符(.)匹配任意字符,包括换行符(s=true)。然而,我写了一个简单的程序,结果显示任意字符根本不匹配换行符。可以在这里找到该程序:

http://play.golang.org/p/pccP52RvKS

英文:

Go's re2 syntax document says that the any character (.) matches any
character, including newline (s=true). However I wrote a simple program whose
result showed that the any character did not match newline at all. The program
can be found here:

http://play.golang.org/p/pccP52RvKS

答案1

得分: 14

像大多数其他(全部?)正则表达式引擎一样,点号不会匹配换行符,除非你在正则表达式中添加“dot all”标志(?s)

我使用你提供的链接进行了测试,它有效。

https://golang.org/pkg/regexp/syntax

英文:

Like most other (all?) regex engines, dot does not match newlines unless you
add the "dot all" flag (?s) to the regex.

I tested this using your link and it worked.

https://golang.org/pkg/regexp/syntax

huangapple
  • 本文由 发表于 2013年11月24日 18:26:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/20173472.html
匿名

发表评论

匿名网友

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

确定