Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get number at the end of string?

Tags:

c#

regex

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 ?

like image 454
Shailesh Jaiswal Avatar asked May 13 '13 10:05

Shailesh Jaiswal


People also ask

How do you find a number in a string?

The number from a string in javascript can be extracted into an array of numbers by using the match method. This function takes a regular expression as an argument and extracts the number from the string. Regular expression for extracting a number is (/(\d+)/).

How do you know if a string ends in a number?

To check if a string ends with a number, call the test() method on a regular expression that matches one or more numbers at the end a string. The test method returns true if the regular expression is matched in the string and false otherwise.

How do you check if a string ends with a number in Python?

The endswith() method returns True if the string ends with the specified value, otherwise False.


1 Answers

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

string contentDbIndex = Regex.Match("ab56cd1234", @"\d+$").Value;
like image 170
p.s.w.g Avatar answered Nov 15 '22 22:11

p.s.w.g