Skip to content

Instantly share code, notes, and snippets.

@yamaguchiyuto
Last active October 9, 2015 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamaguchiyuto/31aa151c475cf52884b4 to your computer and use it in GitHub Desktop.
Save yamaguchiyuto/31aa151c475cf52884b4 to your computer and use it in GitHub Desktop.
Removing URLs and usernames in tweets
import re
def remove_usernames_and_urls(text):
username_removed_text = re.sub('@\w+', '', text) # remove usernames
return re.sub('(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)', '', username_removed_text) # remove urls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment