Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gyli/7404b57da1c0ad10a41cb1f808dbbbf6 to your computer and use it in GitHub Desktop.
Save gyli/7404b57da1c0ad10a41cb1f808dbbbf6 to your computer and use it in GitHub Desktop.
Split string but ignore separator wrapped in brackets
import re
example = """Ann,Bob,Cat(Tom,Max),Dave"""
re.split(r',(?![^\(\)]*\))', example)
# Output:
# ['Ann', 'Bob', 'Cat(Tom,Max)', 'Dave']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment