当前位置:  开发笔记 > 编程语言 > 正文

使用正则表达式匹配两个标签之间的所有内容?

如何解决《使用正则表达式匹配两个标签之间的所有内容?》经验,为你挑选了1个好方法。

如何在两个标签之间匹配(PCRE)所有内容?

我试过这样的事情:

(.*)

但它对我来说效果不佳..

我对正则表达式有点新意,所以我希望有人能够向我解释如何实现这一点,如果它可以用正则表达式来实现的话.

谢谢



1> Owen..:
$string = '
text
'; $regex = '#(.*?)#s'; preg_match($regex, $string, $matches); print_r($matches); // $matches[1] =
text

解释:

(.*?) = non greedy match (match the first  it finds
    s = modifier in $regex (end of the variable) allows multiline matches
        such as 'stuff
                 more stuff
                 '

推荐阅读
殉情放开那只小兔子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有