Skip to content

Instantly share code, notes, and snippets.

@wardi
Created November 17, 2012 17:41
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 wardi/4098030 to your computer and use it in GitHub Desktop.
Save wardi/4098030 to your computer and use it in GitHub Desktop.
splitting on | with escaped \|'s and escaped \\'s
def split_bars(v):
i = iter(v.split('|'))
while True:
part = next(i)
while part.endswith('\\'):
part = part[:-1] + '|' + next(i)
yield part.replace('\\\\', '\\')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment