F: How can I make re.sub() replace patterns across newlines

Karl Pflästerer sigurd at 12move.de
Sun Feb 1 20:15:19 EST 2004


Viktor Rosenfeld <- rosenfel at informatik.hu-berlin.de wrote:

> I want to strip a JAVA file of /* */ like comments.  Unfortunately, the
> simple regexp "\/\*.*\*\/" only works on comments, that are on one line. 
> Is there a simple way to remove comments that go across several lines with
> python regexp's?  I tried re.M to no avail.

You must use re.S

,----[ Python lib reference ]
| `S'
| 
| `DOTALL'
|      Make the `.' special character match any character at all,
|      including a newline; without this flag, `.' will match anything
|      _except_ a newline.
`----


   KP

-- 
Männer der Wissenschaft! Man sagt ihr viele nach, 
aber die meisten mit Unrecht.  
                             Karl Kraus 'Aphorismen'



More information about the Python-list mailing list