Skip to content

Instantly share code, notes, and snippets.

@lppier
Last active December 28, 2020 10:29
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 lppier/52daf623f8caae6357608130c168078e to your computer and use it in GitHub Desktop.
Save lppier/52daf623f8caae6357608130c168078e to your computer and use it in GitHub Desktop.
regex python cheatsheet
# Remove URLs
text_clean = [re.sub(r'http\S+', '', t) for t in text]
# Remove new lines \n
text_clean= [t.strip().replace('\n', ' ') for t in text_clean]
# Remove emails
text_clean = [re.sub(r'[\w\.-]+@[\w\.-]+', '', t) for t in text_clean]
# Remove single quotes
data = [re.sub("\'", "", sent) for sent in data]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment