Regex需要删除不需要的字符


Regex need to remove unwanted characters

在这里回答了我最近关于使用HTML的regex的问题(谢谢大家)之后,我决定最后一次使用regex。我的目标是使用cURL:从以下HTML代码中获取updateXXXX

(...)<input type="hidden" id="_postupdate" name="_postupdate" value="updateXXXX" /><input type="hidden"(...)

使用

$regex = '/name="_postupdate" value="([^"]*)" '/><input type="hidden"/s';
if ( preg_match($regex, $page, $list) )
echo $list[0];

我设法得到了这个输出:

name="_postupdate" value="updateXXXX" />

我相信有一个简单的方法可以删除:

name="_postupdate" value="

" />

再次感谢所有的建议和帮助:)

echo $list[0];更改为echo $list[1];

当您只想要捕获的组([^"]*)时,您当前正在输出整个匹配。

$list[1]中应该有实际结果。尝试print_r($list)。