Created
April 23, 2019 00:59
-
-
Save JSeam2/5af5efd737e39b8f63f1ce31d10fd43f to your computer and use it in GitHub Desktop.
extract username from twitter url
This file contains 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 | |
strings = [ | |
"http://www.twitter.com/#!/donttrythis", | |
"http://twitter.com/KimKardashian", | |
"http://www.twitter.com/#!/KourtneuyKardash/following", | |
"http://twitter.com/#!/jasonterry31/lists/memberships", | |
] | |
username_pattern = re.compile("(https://|http://)?(www\.)?twitter\.com/(#!/)?(\w+)*") | |
for string_tomatch in strings: | |
result = username_pattern.match(string_tomatch) | |
print(result.group(4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment