开发者

How to get the integer part from a string using regex

开发者 https://www.devze.com 2023-02-19 18:14 出处:网络
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:
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号