I have a long string like this and I want to extract all items after Invalid items
, so I expect regex returns a list like
['abc.def.com', 'bar123', 'hello', 'world', '1212', '5566', 'aaaa']
I tried using this pattern but it gives me one group per match
import re
test = 'Valid items: (aaa.com; bbb.com); Invalid items: (abc.def.com;); Valid items: (foo123;); Invalid items: (bar123;); Valid items: (1234; 5678; abcd;); Invalid items: (hello; world; 1212; 5566; aaaa;)'
re.findall(r'Invalid items: \((.+?);\)', test)
# ['abc.def.com', 'bar123', 'hello; world; 1212; 5566; aaaa']
Is there a better way to do this with regex?
thanks