如何在正则表达式中跨多行匹配任何字符? [英] How do I match any character across multiple lines in a regular expression?

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

问题描述

例如,此正则表达式

(.*)<FooBar>

将匹配:

abcde<FooBar>

但是我如何才能使其跨多行匹配?

But how do I get it to match across multiple lines?

abcde
fghij<FooBar>

推荐答案

它取决于语言,但是应该有一个可以添加到正则表达式模式的修饰符.在PHP中是:

It depends on the language, but there should be a modifier that you can add to the regex pattern. In PHP it is:

/(.*)<FooBar>/s

最后的 s 使点与所有字符(包括换行符)匹配.

The s at the end causes the dot to match all characters including newlines.

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

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