RegEx / PHP-提取字符串中的最后一个数字[重复]

问题描述 投票:-1回答:1

字符串示例:1foo22bar333hello4444world55555

我需要能够从具有这种结构的字符串中提取55555

试过几次-但没有运气。没有人为我工作。有人可以帮忙吗?

preg_replace('/[^0-9]/', '', $str);
preg_replace('/[0-9]+/', '', $str);
preg_match_all('!\d+!', $str, $matches);
filter_var($str, FILTER_SANITIZE_NUMBER_INT);
php regex
1个回答
-1
投票

尝试此正则表达式:

preg_match_all("/[0-9]+$/", $str, $matches);

尝试here

© www.soinside.com 2019 - 2024. All rights reserved.