Wildcard for string replacement?!?!

Max M maxm at mxm.dk
Mon Mar 10 20:29:59 CET 2003


Perverted Orc wrote:
> Hello everyone!
> I 'm working for over a week on this script but I can't make my way out. The
> whole idea is to replace (better say delete) anything that stands between
> the <td> and</td> tag of an html file.


If that really is all you want, the easiest way to do it is probably to 
use regular expressions. Which are like wildcards on steroids.

###################################

content = " <td>test1</td>k ælk\n<td>test2</td>lkæ\nlk <td>test3</td>"

import re

itemReg = re.compile('<td>(.*?)</td>', re.I|re.S)
items = itemReg.findall(content)

for item in items:
     print item

 >>>test1
 >>>test2
 >>>test3

-- 

hilsen/regards Max M Rasmussen, Denmark

http://www.futureport.dk/
Fremtiden, videnskab, skeptiscisme og transhumanisme





More information about the Python-list mailing list