Regex match string that ends with number

user2217084 picture user2217084 · May 20, 2015 · Viewed 22k times · Source

What is a regex to match a string that ends with a number for example

"c1234" - match
"c12" - match
"c" - no match

Tried this but it doesn't work

(?|c(?|[0-9]*$))

Thanks again,

The beggining string needs to be specific too

Answer

Denys Séguret picture Denys Séguret · May 20, 2015

Just use

\d$

to check your string ends with a digit

If you want your string to be a "c" followed by some digits, use

c\d+$