How to get the integer part from a string using regex
string $str = "hello768gonf123开发者_高级运维";
How do I get the numbers at the end (i.e. 123
) using regex?
If the integer is always found at the end of the string(hello768gonf123
), you can use:
(\d+)$
If you want to capture the integer closer to the end (123
from hello768gonf123foo
) you can use:
(\d+)\D*$
The regexp ".*([0-9]+)" matches anything followed by a series of one or more digits, and returns the digits as the (only) capture group.
精彩评论