I have an overly complicated regex that as far as I know is correct
route = r"""[\s+|\(][iI](\.)?[vV](\.)?(\W|\s|$)?
|\s intravenously|\s intravenous
|[\s|\(][pP](\.)?[oO](\.)?(\W|\s|$)
|\s perorally|\s?(per)?oral(ly)?|\s intraduodenally
|[\s|\(]i(\.)?p(\.)?(\W|\s|$)?
|\s intraperitoneal(ly)?
|[\s|\(]i(\.)?c(\.)?v(\.)?(\W|\s|$)?
|\s intracerebroventricular(ly)?
|[\s|\(][iI](\.)?[gG](\.)?(\W|\s|$)?
|\s intragastric(ly)?
|[\s|\(]s(\.)?c(\.)?(\W|\s|$)?
|subcutaneous(ly)?(\s+injection)?
|[\s|\(][iI](\.)?[mM](\.)?(\W|\s|$)?
|\sintramuscular
"""
With re.search I manage to get one of the numerous patterns if it is a string
s = 'Pharmacokinetics parameters evaluated after single IV or IM'
m = re.search(re.compile(route, re.X), s)
m.group(0)
' IV '
I read somewhere else to use re.findall to find all the occurrences.
In my dreams, this would return:
['IV', 'IM']
Unfortunately instead the result is:
[('',
'',
' ',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
''),
('',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'')]