I am quite new to python and regex (regex newbie here), and I have the following simple string:
s=r\"\"\"99-my-name-is-John-Smith-6376827-%^-1-2-767980716\"\
I have been playing around with several of these solutions, but many seem to fail if there are no numeric digits at the end of the string. The following code should work.
import re
W = input("Enter a string:")
if re.match('.*?([0-9]+)$', W)== None:
last_digits = "None"
else:
last_digits = re.match('.*?([0-9]+)$', W).group(1)
print("Last digits of "+W+" are "+last_digits)