1

regular expression grouping across multiple lines

view story
linux-howto

http://www.unix.com – Code: cat book.txt book1 price 23       sku  1234       auth  Bill book2 sku  1233       price 22       auth  John book3 auth  Frank       price 24 book4 price 25       sku  129       auth  Tod import re f = open('book.txt', 'r') text = f.read() f.close() m = re.findall(r'(\w{5})\sprice\s(\d+)', text) m [('book1', '23'), ('book4', '25')] desired output: [('book1', '23'), ('book2', '22'), ('book3', '24') ('book4', '25') (HowTos)