Skip to content

Instantly share code, notes, and snippets.

@behnood-eghbali
Last active March 16, 2020 16:08
Show Gist options
  • Save behnood-eghbali/4977629efe8235bdc4ddaf68dfe7fc30 to your computer and use it in GitHub Desktop.
Save behnood-eghbali/4977629efe8235bdc4ddaf68dfe7fc30 to your computer and use it in GitHub Desktop.
Splitting Strings on Any of Multiple Delimiters in Python
text = "Python's built-in interfaces to operating-system services make it ideal for writing portable, maintainable system-administration tools and utilities (sometimes called shell tools)."
import re
fields = re.split(r'[;,.()?!\s]\s*', text)
fields = filter(None, fields)
print(fields)
#["Python's", 'built-in', 'interfaces', 'to', 'operating-system', 'services', 'make', 'it', 'ideal', 'for', 'writing', 'portable', 'maintainable', 'system-administration', 'tools', 'and', 'utilities', 'sometimes', 'called', 'shell', 'tools']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment