python regular expression

Gary Herron gherron at islandtraining.com
Fri Nov 21 18:27:57 EST 2003


On Friday 21 November 2003 03:03 pm, eddieNOSPAM at eddiecentral.net wrote:
> I am trying to edit a bunch of files that are similar. I want to remove all
> the ASP code that appears before the <HTML> tag. Can some one help me with
> a regex that can replace everything before the <HTML> tag with nothing?

You don't need a regular expression for that.  Just find the index of
the first occurrence of <HTML> and slice away.

i = data.find('<HTML>')  # i=-1 means not found
if (i != -1)
  data = data[i:]

Gary Herron







More information about the Python-list mailing list