Created
November 21, 2015 23:09
-
-
Save walkerdb/48487741912253032106 to your computer and use it in GitHub Desktop.
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
import re | |
def split_extents(extent_text): | |
# splits by " and ", " in ", and each of the following characters: ,([ | |
regex_to_split_by = r"\,|\[|\(| and | in " | |
extent_list = filter(None, re.split(regex_to_split_by, extent_text)) | |
# the re.split() function removes the characters it splits by, so if we want to | |
# preserve the opening parentheses and brackets, we need to add those back | |
extent_list = ["(" + extent if extent.endswith(")") else extent for extent in extent_list] | |
extent_list = ["[" + extent if extent.endswith("]") else extent for extent in extent_list] | |
# removing leading and trailing whitespace using the built-in strip() function | |
extent_list = [extent.strip(" ") for extent in extent_list] | |
return extent_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment