Split string with multiple separators from an array (Python)

Viewed 646

Given an array of separators:

columns = ["Name:", "ID:", "Date:", "Building:", "Room:", "Notes:"]

and a string where some columns were left blank (and there is random white space):

input = "Name:      JohnID:123:45Date:  8/2/17Building:Room:Notes:  i love notes"

How can I get this:

["John", "123:45", "8/2/17", "", "", "i love notes"]

I've tried simply removing the substrings to see where I can go from there but I'm still stuck

import re
input = re.sub(r'|'.join(map(re.escape, columns)), "", input)
2 Answers
Related