Regular Expressions
Jeremy Jones
zanesdad at bellsouth.net
Wed Aug 25 12:24:01 EDT 2004
Oriana wrote:
>hi!
>
> I've been working with Python for about two months now but I just
>started learning about regular expressions.
> My question is the following. I have a source file that contains
>code and comments. A piece of the comments contains a revision history
>that I would like to erase completely from the file since I never
>update it and I don't use it anymore. The file looks something like
>
>/****************************************
>* Some info
>*
>* More info
>*
>*----------------------------------------
>*
>* Revision History:
>*
>* blah
>* blah
>* blah
>*
>*----------------------------------------
>
>
>I would like to write some sort of regular expression to replace all
>the text from the first dotted line up to the first asterisk that it's
>followed either by another asterisk or by another *----
>line.....please help, I don't know where to start!!!
>
>
On this particular problem, you might be better served to not use
regexes to match the whole thing. The way that I would go about it
(this is obviously not the only answer, but it'll work) is to read in
the file line by line and rely on state variables to let you know when
to write out and when not to write out your current line. This is kinda
sketchy, but you get the idea. HTH
Jeremy
More information about the Python-list
mailing list