Q:

regex to match the last five numbers in a row

I need a regular expression to find the last occurrence of 5 consecutive digits in a string. This is what I have right now:
([0-9]{5})[a-zA-Z]*$

This only matches some of my test strings.
In a live environment the numbers will change, but for testing I expect to capture the substring '12345' in each of the test strings below:

D012345
D012345AS
D012345RM-67
D12345D
12345D67
TEST-Str12345ing-rm6

A:

Updated
Works w/ global flag, passes all tests. No capture group required.:
[0-9]{5}(?![0-9])(?!.*[0-9]{5})

Live example:
http://www.regexr.com/3c875
Let's break this down:
Match any instance of five digits
[0-9]{5}

But the instance cannot be immediately followed by another digit - this way,
we always get the last five in any group of consecutive numbers.
(?![0-9])

Lastly, make sure no further groups of consecutive numbers exist that have 
more than five digits.
(?!.*[0-9]{5})

