import re
pattern = r'http://myblog.com/posts/(\S*)/comments/(\d*)'
regex_object = re.compile(pattern)
URL = 'http://myblog.com/posts/john-travolta/comments/5'
match = regex_object.match(URL)
if match:
param1, param2 = match.groups()
print(param1)
# john-travolta
print(param2)
# 5