re.finditer with lookahead and lookbehind

Christian mining.facts at googlemail.com
Wed Jun 20 15:30:10 CEST 2012


Hi,

i have some trouble to split a pattern like s.   Even have this
problems with the first and last match. Some greedy problems?

Thanks in advance
Christian

import re

s='v1=pattern1&v2=pattern2&v3=pattern3&v4=pattern4&v5=pattern5&x1=patternx'
pattern =r'(?=[a-z0-9]+=)(.*?)(?<=&)'
regex = re.compile(pattern,re.IGNORECASE)
for match in regex.finditer(s):
	print  match.group(1)

My intention:
pattern1
pattern2
pattern3
pattern4
pattern5
patternx



More information about the Python-list mailing list