preg_match的正则表达式

时间:2015-10-22 12:49:03

标签: php regex

我得到了以下字符串:

ElFTkSuQmCC" alt="" width="auto" height="auto" /></td>
<td style="padding: 10px;">XX,X%</t

并希望拥有&#34; XX,X&#34;,所以我构建了以下正则表达式:

/QmCC" alt="" width="auto" height="auto" \/><\/td>\n<td style="padding: 10px;">(.*?)%/

我在网上进行了测试并获得了XX,X的匹配,但是当我尝试使用以下代码在php中执行它时 preg_match_all('/REGEX/',$string,$match);

它没有匹配。你有什么建议吗? String肯定在那里。 var_dump($match)给了我一个空数组。

谢谢!

2 个答案:

答案 0 :(得分:3)

问题在于换行符。在你的正则表达式中,有\n。请改用\r\n,它会起作用。

答案 1 :(得分:0)

将X视为字符串中的数字:

$pattern = '/(\d{2},\d{1,2})/';

preg_match_all($pattern, $string, $match);
相关问题