Hi guys I want to split the following string that are parsed from a text file using perhaps regular expression in python.
Inside the text file(filename.txt)
pattern = '(?<!\d)[\.=]|[\.=](?!\d)'
f = open('filename.txt','rb')
for line in data_file:
str_values = re.split(pattern, line.rstrip())
['iPhone', 'Case', '1', 'left', '1099.0.2']
['new', 'phone', 'newwork', 'bla', 'jpg']
If you have regular enough input data that you can always split first at the
= character, then split the first half at every
. character, I would skip regex entirely, as it is complicated and not very pretty to read.
Here's an example of doing just that:
s = 'new.phone.newwork=bla.jpg' l = str.split(s.split('='), '.') + s.split('=')[1:]