Regular Expression To Get The Number At The End Of A String

Category: Numbers

A regular expression that matches the number at the end of a string.

I am sure you have had a time when you needed the number at the end of a string of characters. Perhaps it was a long username and you needed to parse out the last x numbers or maybe you were parsing a parameter but needed to get rid of the index number. Well, if this is something you deal with on a regular basis, then take a look at this little snippet to make your life easier.

/\d+$/

Matches:

  • RegexPattern123
  • Word345
  • 789

Non-matches:

  • Regex123Pattern
  • Word345 Word
  • Abcd

See Also:

Rate The Regex
Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.