Python Regex to find whitespace, end of string, and/or word boundary

后端 未结 2 928
我寻月下人不归
我寻月下人不归 2021-01-24 02:29

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

2条回答
  •  时光取名叫无心
    2021-01-24 02:53

    ... 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']
    

提交回复
热议问题