Skip to content

Instantly share code, notes, and snippets.

@lisanka93
Created July 13, 2020 15:59
Show Gist options
  • Save lisanka93/bbcc52403ba394daf3af2996ec0216a5 to your computer and use it in GitHub Desktop.
Save lisanka93/bbcc52403ba394daf3af2996ec0216a5 to your computer and use it in GitHub Desktop.
regular expressions to remove punctuation
import re
#letters only
raw_text = "this is a test. To demonstrate 2 regex expressions!!"
letters_only_text = re.sub("[^a-zA-Z]", " ", raw_text)
#keep numbers
letnum_text = re.sub("[^a-zA-Z0-9\s]+", " ",raw_text )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment