是否去正则表达式的任何charcter匹配换行符 [英] Does go regexp's any charcter match newline

查看:102
本文介绍了是否去正则表达式的任何charcter匹配换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Go的 re2语法文档表示任何字符(。)都与任何字符匹配字符,包括换行符(s = true)。但是我写了一个简单的程序,其结果显示任何字符都不符合换行符。该程序可以在这里找到: http://play.golang.org/p/pccP52RvKS 。我很困惑。



任何帮助将不胜感激,并且在此先感谢您。

解决方案

像大多数其他(所有)正则表达式引擎一样,除非将点全部标记(?s)添加到正则表达式,否则点不匹配换行符。



我使用你的链接测试了它,它工作。


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. I am really confused.

Any help will be appreciated, and thanks in advance.

解决方案

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.

这篇关于是否去正则表达式的任何charcter匹配换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆