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

正则匹配 回车换行。

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 14:18:521834browse

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

正则 PHP JavaScript HTML


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


抓到这个'PHP';

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

回复讨论(解决方案)

\s 写成了 s

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

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

\s 写成了 s

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

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


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

其实这样写好点
$pattern_Title =   "/target=\"\_blank\"\>.*\[\s\S]*\/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);
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);
Array
(
    [0] => Array
        (
            [0] => target="_blank">
 
        PHP
            
        )

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

)

其实这样写好点
$pattern_Title =   "/target=\"\_blank\"\>.*\[\s\S]*\/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);
Array
(
    [0] => Array
        (
            [0] => target="_blank">
 
        PHP
            
 
            
        )

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

)

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


多谢各位!

Statement:
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
Previous article:ubuntu 13.04 nginx php 安装Next article:PHP with GUI 之难