如何在正则表达式中匹配多行中的任何字符? [英] How do I match any character across multiple lines in a regular expression?
本文介绍了如何在正则表达式中匹配多行中的任何字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如这个正则表达式
(.*)<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屋!
查看全文