Skip to content

Instantly share code, notes, and snippets.

@aoirint
Created March 1, 2020 23:52
Show Gist options
  • Save aoirint/2f867aa58b041fbbbdf55c3a64a692c8 to your computer and use it in GitHub Desktop.
Save aoirint/2f867aa58b041fbbbdf55c3a64a692c8 to your computer and use it in GitHub Desktop.
split Twitter URL regex (no slash escape)
import re
from urllib.parse import urlparse
s = 'https://twitter.com/nanashiwan/status/1234137030084349952'
# s = 'https://twitter.com/nanashiwan/status/1234137030084349952/photo/1'
urlp = urlparse(s)
m = re.match(r'^/(.+)/status/([^/]+)(/.+)?', urlp.path)
m.groups()
# ('nanashiwan', '1234137030084349952', None)
# ('nanashiwan', '1234137030084349952', '/photo/1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment