用于在字符串前后捕获的preg匹配


preg match for capturing before and after a string

我想从我拥有的rss提要链接中提取数字(以粗体给出)。如何使用preg_match()实现它?

。。。。com/photo/51671645.cms

只需使用这个简单的模式com/photo/('d+).cms:

preg_match('|com/photo/('d+).cms|', 'com/photo/51671645.cms', $matches);
$number = $matches[1];