Last active
March 16, 2020 16:08
-
-
Save behnood-eghbali/4977629efe8235bdc4ddaf68dfe7fc30 to your computer and use it in GitHub Desktop.
Splitting Strings on Any of Multiple Delimiters in Python
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
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