Created
March 1, 2020 23:52
-
-
Save aoirint/2f867aa58b041fbbbdf55c3a64a692c8 to your computer and use it in GitHub Desktop.
split Twitter URL regex (no slash escape)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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