re.MULTILINE
affects the meaning of the ^
and $
anchors. What I think you want here is re.DOTALL
, without which the .
character will never match a newline.
To match all of the text up to the next blank line, you'd use something like (.*?)\n\s*\n
. This seems to do what you're looking for?
p = re.compile(r'texture\s+(\S+)\s+\[(\d+\s+\d+\s+\d+)\]\s+(.*?)\n\s*\n', re.DOTALL)
matches = p.findall(input)
for match in matches:
print match[0]
print match[1]
print match[2]
print "---------------"
On your sample text, this produces:
mytexture
640 480 1
'BE4C16FFBD4B15FFBD4B15FFBD4B15FFBD4B15FFBE4C16FFBE4C16FFBD4B15FFBD4B15FF'
'BE4C16FFBE4C16FFBD4B15FFBC4A14FFBC4A14FFBC4A14FFBC4A14FFBC4A14FFBE4C16FF'
'BF4C16FFBF4C16FFBE4B15FFBE4B15FFBC4913FFBC4913FFBC4913FFBB4812FFBC4913FF'
'BC4A14FFBB4913FFBB4812FFBB4812FFBA4812FFBA4812FFBB4913FFBC4A16FFBB4915FF'
'B84612FFB84612FFB94713FFB84612FFB64410FFB64410FFB64410FFB4420EFFB3410DFF'
'FB03E0AFFB13F0BFB13F0BFFAE3C08FFAA3804FFAD3B07FFB03E0AFFB3410DFFB4420EFF'
'B4400DFFB13D0AFFB23C0AFFB03C09FFB23E0BFFB5410EFFB74310FFB94512FFB84411FF'
---------------
mytexture2
640 480 1
'BE4C16FFBD4B15FFBD4B15FFBD4B15FFBD4B15FFBE4C16FFBE4C16FFBD4B15FFBD4B15FF'
'BE4C16FFBE4C16FFBD4B15FFBC4A14FFBC4A14FFBC4A14FFBC4A14FFBC4A14FFBE4C16FF'
(... etc...)
---------------