使用 Erlang re 模块的多行正则表达式
无法让 Erlang 重新工作于多行,请帮忙!
> re:run("hello,\nworld", "o,.*w", [multiline]).
nomatch
> re:run("hello,\nworld", "o,.*w", [multiline, {newline, lf}]).
nomatch
> {ok, MP} = re:compile("o,.*w", [multiline]).
{ok,{re_pattern,0,0,
<<69,82,67,80,55,0,0,0,2,0,0,0,7,0,0,0,0,0,0,0,111,0,
119,...>>}}
> re:run("hello,\nworld", MP).
nomatch
> re:run("hello,\nworld", ",\nw").
{match,[{5,3}]}
Failed to get Erlang re work for multiline, please help!
> re:run("hello,\nworld", "o,.*w", [multiline]).
nomatch
> re:run("hello,\nworld", "o,.*w", [multiline, {newline, lf}]).
nomatch
> {ok, MP} = re:compile("o,.*w", [multiline]).
{ok,{re_pattern,0,0,
<<69,82,67,80,55,0,0,0,2,0,0,0,7,0,0,0,0,0,0,0,111,0,
119,...>>}}
> re:run("hello,\nworld", MP).
nomatch
> re:run("hello,\nworld", ",\nw").
{match,[{5,3}]}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
multiline
选项仅告诉正则表达式引擎将^
不仅视为字符串的开头,而且还视为新行的开头,并且还告诉引擎将$
不仅视为字符串的结尾,而且视为行的结尾。请尝试这样做:
dotall
选项将告诉正则表达式引擎也让换行符与点元字符匹配。The
multiline
option only tells the regex engine to treat^
not only as the start of the string, but also as the start of a new line and it also tells the engine to treat$
not only as the end of the string, but as the end of a line.Try this instead:
The
dotall
option will tell the regex engine to also let line breaks be matched by the DOT meta character.使用 dotall 选项,即
use the dotall option, i.e.