【发布时间】:2012-10-04 13:52:39
【问题描述】:
现在这主要是学术性的,因为我可以通过其他方式获得相同的结果,但是……它一直困扰着我,我确信使用正则表达式可以以某种方式实现。
我想使用 PHP 的 preg_replace 来替换内容:
Content: “String <tag>This is some content, which contains newlines and quotation marks.</tag> and other unrelated content”.
Regex: /<tag>(.*)<\/tag>/sU
Replace: “String of other content, including matched pattern $1”
但是问题是,我想去掉元素之间的任何换行符和/或引号。什么正则表达式可以让我这样做?
【问题讨论】:
-
也许这会让你朝着正确的方向前进:pagecolumn.com/tool/all_about_html_tags.htm 此外,还有很多关于这个的话题。那么:你尝试了什么或者你想要达到什么目标?也许您正在尝试使用正则表达式来构建特定的 php 函数。?
-
是的,不幸的是,很明显正则表达式不是解决方案,但这个问题引起了我的兴趣,所以我想知道它是否可能。
标签: php regex preg-replace pcre