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\"\
Your Regex
should be (\d+)$
.
\d+
is used to match digit (one or more)$
is used to match at the end of string.So, your code should be: -
>>> s = "99-my-name-is-John-Smith-6376827-%^-1-2-767980716"
>>> import re
>>> re.compile(r'(\d+)$').search(s).group(1)
'767980716'
And you don't need to use str
function here, as s
is already a string.