question on pattern

John Machin sjmachin at
Fri Jun 7 18:40:41 EDT 2002

Ulrich Pfisterer <ulrich.pfisterer at> wrote in message news:<3D007E96.3010505 at>...
> 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.

You have got an answer to your problem of how to get DOTALL behaviour
with .findall(). However you should be aware that your pattern can
match strings that are not syntactically C or C++ comments. Here is an
example from page 172 of "Mastering Regular Expressions" by Jeffrey E.
F. Friedl:

   const char *cstart = "/*", *cend = "*/";

I'd agree that it's a pathological case. I'm just pointing out that in
most work on program source files, to be 100% correct you need to have
a lexical analyser for the language in question. Regexes won't take
you the whole distance.

More information about the Python-list mailing list