I am using re in python 2.7.5 for regex. I am trying to have it match foobar.com/1, `foobar.com/12, foobar.com/123, or
re
foobar.com/1
`foobar.com/12
foobar.com/123
foobar\.com/\d{1,4}\b
Will do the trick.
... or you could use the negative lookahead (?!...) to make sure there is not a fifth digit.
(?!...)
>>> re.findall(r'foobar[.]com/\d{1,4}(?!\d)', comment.body) ['foobar.com/1319', 'foobar.com/567', 'foobar.com/1302', 'foobar.com/201']