再次使用PHP正则表达式
以下两者之间有什么区别吗再次使用PHP正则表达式,php,regex,Php,Regex,以下两者之间有什么区别吗 preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string ); preg_replace('@]*?>.@si',''.$string); 及 preg_replace('@]*>.@si',''.$string); 是的 考虑这个字符串示例 <script>bla</script><script>hello</scrip
preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string );
preg_replace('@]*?>.@si',''.$string);
及
preg_replace('@]*>.@si',''.$string);
是的
考虑这个字符串示例
<script>bla</script><script>hello</script>
额外的
?
将反转表达式的贪婪性(它们在php中默认为贪婪):
将匹配/a+b/
中的aaab
aaab
将匹配/a*b/
中的aaab
aaab
将匹配/a*?b/
aaab中的
b
将与/a+?b/
aaab
仔细看看,@alex:non-greedy版本(添加了
?
)首先列出;第二个是贪婪。“但是分析是正确的。”艾伦:哎呀,我今天一定是生活在相反的环境中。我将编辑:)
<script>bla</script><script>hello</script>
$dom = new DOMDocument;
$dom->loadHTML($string);
$scripts = $dom->getElementsByTagName('script');
$styles = $dom->getElementsByTagName('style');