Home > Backend Development > PHP Tutorial > 正则匹配 回车换行。

正则匹配 回车换行。

WBOY
Release: 2016-06-23 14:18:52
Original
1631 people have browsed it

本帖最后由 liuser_cn 于 2013-08-09 20:51:54 编辑

正则 PHP JavaScript HTML


$pattern_Title =   "/target=\"\_blank\"\>.*\<\/a\>s+\<\/h4\>/is";//。。。。
Copy after login


抓到这个'PHP';

<h4>			<a id="4658205654481332717" istitle="true" href="javascript:void(0);" onclick="makeDetailUrl(this, '/search/showDocDetails?', '4658205654481332717', 'ucs09', 'PHP');" target="_blank">		PHP			</a>			</h4>
Copy after login


回复讨论(解决方案)

\s 写成了 s

$pattern_Title =   "/target=\"\_blank\"\>.*\<\/a\>\s+\<\/h4\>/is";
Copy after login
Copy after login
Copy after login

其实这样写好点
$pattern_Title = "/target=\"\_blank\"\>.*\<\/a\>[\s\S]*\<\/h4\>/is";//。。。。

\s 写成了 s

$pattern_Title =   "/target=\"\_blank\"\>.*\<\/a\>\s+\<\/h4\>/is";
Copy after login
Copy after login
Copy after login

应该不是这个原因,得频繁的用上\s


$pattern_Title = "/target=\"\_blank\"\>\s*(\S*)\s*\<\/a\>\s*\<\/h4\>/i"; //标题
求简化高质量正则表达式- -!

其实这样写好点
$pattern_Title = "/target=\"\_blank\"\>.*\<\/a\>[\s\S]*\<\/h4\>/is";//。。。。

问一下,修饰符s用了之后,直接抓到低结束不了,比如说我想在这里结束,需要用什么来声明吗?

$s =<<< TXT<h4>            <a id="4658205654481332717" istitle="true" href="javascript:void(0);" onclick="makeDetailUrl(this, '/search/showDocDetails?', '4658205654481332717', 'ucs09', 'PHP');" target="_blank">         PHP            </a>             </h4>TXT;$pattern_Title = '#target="_blank">(.*)</a>\s+</h4>#is';preg_match_all($pattern_Title, $s, $r);print_r($r);
Copy after login
Copy after login
Array
(
[0] => Array
(
[0] => target="_blank">

PHP



)

[1] => Array
(
[0] =>

PHP

)

)

$pattern_Title = '#target="_blank">\s*(.*)\s*</a>#is';preg_match_all($pattern_Title, $s, $r);print_r($r);
Copy after login
Array
(
[0] => Array
(
[0] => target="_blank">

PHP

)

[1] => Array
(
[0] => PHP

)

)

其实这样写好点
$pattern_Title = "/target=\"\_blank\"\>.*\<\/a\>[\s\S]*\<\/h4\>/is";//。。。。

$s =<<< TXT<h4>            <a id="4658205654481332717" istitle="true" href="javascript:void(0);" onclick="makeDetailUrl(this, '/search/showDocDetails?', '4658205654481332717', 'ucs09', 'PHP');" target="_blank">         PHP            </a>             </h4>TXT;$pattern_Title = '#target="_blank">(.*)</a>\s+</h4>#is';preg_match_all($pattern_Title, $s, $r);print_r($r);
Copy after login
Copy after login
Array
(
[0] => Array
(
[0] => target="_blank">

PHP



)

[1] => Array
(
[0] =>

PHP

)

)

\s 写成了 s
$pattern_Title =   "/target=\"\_blank\"\>.*\<\/a\>\s+\<\/h4\>/is";
Copy after login
Copy after login
Copy after login


多谢各位!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template