php preg_match_all自定义模式

时间:2011-08-11 13:39:39

标签: php regex preg-match-all

我有一个像

这样的字符串
$string = ">xyz, >abc hi there and also hi to >nrm";

我想找到“>”旁边出现的所有单词标志 例如,在上面的字符串中,它将返回所有单词xyz,abc和nrm

我尝试了一些方法,但没有任何结果

帮助我们,并提前致谢

1 个答案:

答案 0 :(得分:3)

您可以执行以下操作:

preg_match_all("/>(\w+)/", $string, $matches);
// $matches[1] contains the matches you want.

另请参阅:Example of it in action on Ideone