如何使用正则表达式从字符串中获取整数部分

use*_*104 1 regex string integer

string $str  = "hello768gonf123";
Run Code Online (Sandbox Code Playgroud)

如何123使用正则表达式获得最后的数字(即)?

cod*_*ict 5

如果始终在string(hello768gonf123)的末尾找到整数,则可以使用:

(\d+)$
Run Code Online (Sandbox Code Playgroud)

如果要捕获靠近末尾(123hello768gonf123foo)的整数,可以使用:

(\d+)\D*$
Run Code Online (Sandbox Code Playgroud)