using a regex to split your string seems a bit overkill: the split()
method may be just what you need.
anyway, if you really need to match the regular expression to split your string, you should use the re.split()
method, which breaks the string into regular expression matching.
also use the correct regular expression for splitting:
>>> line = 'path:bte00250 Alanine, aspartate and glutamate metabolism path:bte00330 Arginine and proline metabolism' >>> re.split(' (?=path:)', line) ['path:bte00250 Alanine, aspartate and glutamate metabolism', 'path:bte00330 Arginine and proline metabolism']
A group (?=...)
is a statement in the form: an expression matches a space (note the space at the beginning of the expression), followed by the string 'path:'
, without consuming what follows the space.
Adrien plisson
source share