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

后端 未结 2 906
我寻月下人不归
我寻月下人不归 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:44
    foobar\.com/\d{1,4}\b
    

    Will do the trick.

    0 讨论(0)
  • 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']
    
    0 讨论(0)
提交回复
热议问题