Regular Expressions

Max spamhole at
Wed Aug 25 21:50:05 CEST 2004

On Wednesday 25 August 2004 18:02, Oriana wrote:


> 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!!!

Below is some code that will search for the starting and ending *--- lines in 
a specified file and print the whole file with the *--- part being removed.

Hope thats a start,


import re

f = file("somefile.c", "r")
text =

m ="\*-*.*\*-*\n", text, re.DOTALL)

if not m:
        print "nothing found"
        print text[:m.start(0)] + text[m.end(0):]

More information about the Python-list mailing list