如何在字符串末尾获取数字?

时间:2022-09-19 17:57:41

I want to retrive the number sequence which is at the end of string. for e.g.

我想要检索字符串末尾的数字序列。例如

string contentDbIndex = Regex.Match("ab56cd1234", @"\d+").Value;

gives me result 56 but I want the result as 1234. How should I do this ?

给我结果56,但我希望结果为1234.我该怎么做?

1 个解决方案

#1


19  

You can use a end anchor ($) like this:

您可以使用这样的结束锚($):

string contentDbIndex = Regex.Match("ab56cd1234", @"\d+$").Value;

#1


19  

You can use a end anchor ($) like this:

您可以使用这样的结束锚($):

string contentDbIndex = Regex.Match("ab56cd1234", @"\d+$").Value;