I have the following string
'abc[123]defgh ijk[456]lm no[78] pq'
And I would like to extract all parts which are either between the begin of the string and [ or between whitespace and [. For the given string, these are the parts 'abc', 'ijk', and 'no'.
I have the following expression
exp = re.compile(r'\s(.*?)\[')
But I cannot figure out how to add the beginning of the string as an optional expression. How do I have to write the expression to cover both cases?