I'm looking to convert a single string to a list of strings based upon a list of corresponding RegEx values.
My code currently looks like this:
def regexSplit(s, regexList):
retList = [""]*len(regexList)
i = 0
for e in enumerate(regexList):
retList[i] = regex.search(regexList[i], s)
s = s.split(retList[i], 1)[1]
i += 1
return retList
When attempting to run the code, however, I am getting the error:
in regexSplit
s = s.split(retList[i], 1)[1]
TypeError: expected a character buffer object
Goal Example:
I'm trying to get it so that passing values such that if
s = "|Y4000|,03/02/2015,2000,||,|REDLANDS|,|CA|,|92375|"
and
regexList = ['[\w\d]{5}', '[0,1][1-9][/][0-3][0-9][/][\d]{4}', '[-]?[\d]*', '[^|]{0,40}', '[\w\s]{0,30}', '[\w]{2}', '[\d]{0,5}']
the returned list would be:
["Y4000", "03/02/2015", "2000", "", "REDLANDS", "CA", "92375"]
Thanks in advance.
,and then just splitting on,It feels like that's more close to what you want to do.,and"and other such complications...)for r in replacements: s.replace(r,',')that will replace all dividers with commas, then we split on the commas.