PHP正则匹配反斜杠'\'和美元'$'
$content = 1111111td2222222\/td3$; br / br / span style=color:#006600;///span span style=color:#006600;\\\\\//span span style=color:#006600; 第1个\转义字符串的第2个\,字符串为\ /span br / span style=color:#006600; //第3个\转义
$content = '1111111<td>2222222<\/td>3$';
//' \\\\\/ ' 第1个'\'转义字符串的第2个'\',字符串为'\'
//第3个'\'转义第4个'\',相当于 字符串 '\'
//第5个'\'转义第4个'/',相当于 字符串 '/'
//字符合起来为'\\/' 两个'\\' 正则表达式看做'\'
$pattern = '/<td>([0-9]{7,})<\\\\\/td>\d\\$$/';
上面方法out了,使用\Q \E,具体东西看评论 @阿尔法兽
//' \\\\\/ ' 第1个'\'转义字符串的第2个'\',字符串为'\'
//第3个'\'转义第4个'\',相当于 字符串 '\'
//第5个'\'转义第4个'/',相当于 字符串 '/'
//字符合起来为'\\/' 两个'\\' 正则表达式看做'\'
$pattern = '/<td>([0-9]{7,})<\\\\\/td>\d\\$$/';
上面方法out了,使用\Q \E,具体东西看评论 @阿尔法兽
<?php $content = '1111111<td>2222222<\/td>3$'; //'\\\\\/' 第1个'\'转义字符串的第2个'\',字符串为'\' //第3个'\'转义第4个'\',相当于字符串'\' //第5个'\'转义第4个'/',相当于字符串'/' //字符合起来为'\\/' 两个'\\' 正则表达式看做'\' $pattern = '/<td>([0-9]{7,})<\\\\\/td>\d\\$$/'; $result = preg_match_all($pattern, $content, $match_result); if($result) print_r($match_result); else echo("not match");
2. [代码]@阿尔法兽 指点的 跳至 [1] [2] [3] [全屏预览]
$content = '1111111<td>2222222<\/td>3$'; $pattern = "!<td>(\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 跳至 [1] [2] [3] [全屏预览]
Array ( [0] => Array ( [0] => <td>2222222<\/td>3$ ) [1] => Array ( [0] => 2222222 ) )
- 上一篇:获取首字符的拼音首字母
- 下一篇:天天AV - 微信公众平台 - 实例
精彩图集
精彩文章