regular expression to extract text
Marc Boeren
M.Boeren at guidance.nl
Thu Nov 20 11:08:12 EST 2003
Oops, just noted that the data was included below, and not in the given
lines.
Still, the split still works on both lines:
> QEXZUO C26 H31 N1 O3
> 6.164 15.892 22.551 90.00 90.00 90.00
bit1 = line1.split(" ")[0]
bit2 = [v for v in line1.split(" ")[1:] if v]
bit3 = [v for v in line2.split(" ") if v]
>>> bit1
'QEXZUO'
>>> bit2
['C26', 'H31', 'N1', 'O3']
>>> bit3
['6.164', '15.892', '22.551', '90.00', '90.00', '90.00']
You can probably figure out the rest, like testing for a
line0.startswith('----') as a separator and such?
Cheerio, Marc.
More information about the Python-list
mailing list