我有一篇这样的文字:The cat was born on 1980 and lives ...
所以我想用正则表达式获取猫的年龄(文本中可能出现超过 1 次的 4 位数字)。
我正在尝试这个preg_match('/born on [0-9]{4}/', $text, $matches)
但结果是:array('born on 1980')
。我想忽略一年前的一切。
Demo: http://www.phpliveregex.com/p/aYl http://www.phpliveregex.com/p/aYl
将所需的值分组,然后它将成为数组的第一项。
$text = 'The cat was born on 1980 and lives ...';
preg_match('/born on ([0-9]{4})/', $text, $matches);
echo $matches[1];
Output:
1980
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)