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 ) )