import re text='''Consumer Price Index: +0.2% in Sep 2020 Unemployment Rate: +7.9% in Sep 2020 Producer Price Index: +0.4% in Sep 2020 Employment Cost Index: +0.5% in 2nd Qtr of 2020 Productivity: +10.1% in 2nd Qtr of 2020 Import Price Index: +0.3% in Sep 2020 Export Price Index: +0.6% in Sep 2020''' print( re.findall(r'(\S.*):\n\s*(\+?\d[\d.]*%)\s+in\s+(.*)', text) )
Standard input is empty
[('Consumer Price Index', '+0.2%', 'Sep 2020'), ('Unemployment Rate', '+7.9%', 'Sep 2020'), ('Producer Price Index', '+0.4%', 'Sep 2020'), ('Employment Cost Index', '+0.5%', '2nd Qtr of 2020'), ('Productivity', '+10.1%', '2nd Qtr of 2020'), ('Import Price Index', '+0.3%', 'Sep 2020'), ('Export Price Index', '+0.6%', 'Sep 2020')]