python regular expression

G

Guest

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?
 
G

Gary Herron

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
 
P

Peter Hansen

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?

stuff = 'whatever ASP blah\nblah <HTML>more blah blah</HTML>maybe even more'
try:
shortStuff = stuff[stuff.index('<HTML>'):]
except:
shortStuff = stuff

No regex required...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top