A regular expression of PHP matches, the results feel not right?

Source: Internet
Author: User

$content = '

这里是帖子的内容。

这里是帖子的其他内容

$user = $this->session->get('auth');                $baa_id=(int)$_POST['baa_id'];                $time = date('Y-m-d H:i:s');                

这里是帖子的其他内容

';preg_match_all('# ]*>([^(?: )]*)

#',$content,$matches);print_r($matches);

Results of the match:

Array(    [0] => Array        (            

这里是帖子的内容。

) [1] => Array ( [0] => 这里是帖子的内容。 ))

Why can't the content of other tags such as img span between p tags be matched?

Reply content:


$content = '

这里是帖子的内容。

这里是帖子的其他内容

$user = $this->session->get('auth');                $baa_id=(int)$_POST['baa_id'];                $time = date('Y-m-d H:i:s');                

这里是帖子的其他内容

';preg_match_all('# ]*>([^(?: )]*)

#',$content,$matches);print_r($matches);

Results of the match:

Array(    [0] => Array        (            

这里是帖子的内容。

) [1] => Array ( [0] => 这里是帖子的内容。 ))

Why can't the content of other tags such as img span between p tags be matched?

has been updated,preg_match_all('# ]*)>([\s\S]*?)

#',$content,$matches);
This is the complete notation, your problem is that you mistakenly think [^(?: )]The representative is in addition to <>< code=""> >或者

标签以外的匹配。实际上 [^(?: )]等同于 [^?: ]这样看就明白了吧

不用正则,xpath搞定

  • <>
    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.