question on pattern

Harvey Thomas hst at
Fri Jun 7 06:06:58 EDT 2002

Ulrich Pfisterer wrote:
> I want to do a pattern match on a string that spans multiple 
> lines (c++ 
> style comments, re.match('(/\*.*?\*/)', filestring)
> If I use the re.findall(pattern, string) method it only finds those 
> matches that are on a single line. If I use re.match(pattern, string, 
> DOTALL) it spans multiple lines but only finds the first match.
> Any help on this one would be greatly appreciated.
This works:
>>> import re
>>> r = re.compile('/\*.*?\*/', re.DOTALL)
>>> t = '/* a \nmulti-line\ncomment*/   /*another comment*/'
>>> r.findall(t)
['/* a \nmulti-line\ncomment*/', '/*another comment*/']



This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.

More information about the Python-list mailing list