PHP regular match backslash ''and dollar '$'-PHP source code

Source: Internet
Author: User
Tags php regular expression
PHP regular expression matching backslash and dollar $ content = '000000'2222222 <\/td> 3 $ ';

// '\\\\\\/'100' \ 'escape string's 100' \', string is '\'
// 3rd ''\ 'escape 4th'' \', equivalent to the string '\'
// 5th '\' escape 4th '/', equivalent to the string '/'
// The characters are combined into two '\/' regular expressions '\'
$ Pattern = '/([0-9] {7,}) <\\\\/td> \ d \\\ $ /';

The above method is out. use \ Q \ E to view comments.

1. test. php

 2222222 <\/td> 3 $ '; //' \\\\\/'000000' \ 'escape string 100 '\', the string is '\' // 3rd ''\ 'to escape 4th'' \', which is equivalent to the string '\' // 5th ''\ 'to escape 4th '/', equivalent to the string '/' // character combination as '\/' two '\' regular expressions as '\' $ pattern = '/([0-9] {7,}) <\\\\\/td> \ d \\\ $/'; $ result = preg_match_all ($ pattern, $ content, $ match_result); if ($ result) print_r ($ match_result); else echo ("not match ");

2. php code

$content = '11111112222222<\/td>3$'; $pattern = "!(\d{7,})<\Q\/\Etd>\d\Q$\E!"; $result = preg_match_all($pattern, $content, $m);     if($result)     print_r($m); else    echo("not match");

3.output.txt

Array(    [0] => Array        (            [0] => 2222222<\/td>3$        )     [1] => Array        (            [0] => 2222222        ) )

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.