not perfect or tested but<br><br>import re<br><br>chopset.reverse() #: put the longer extensions first<br><br>exts = "|".join([re.escape(x) fro x in chopset)])<br><br>for line in file:<br> print exts.sub("", line)<br>
<br><br><br><div class="gmail_quote">On Fri, Jul 24, 2009 at 9:22 AM, vankayala sailakshman <span dir="ltr"><<a href="mailto:sailakshman9@hotmail.com">sailakshman9@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<br>Hi All, <br>
        
        
        
<p style="margin-bottom: 0in;">Help needed to write a python script!!!</p>
<p style="margin-bottom: 0in;"> Iam a python newbie and my problem
is doing multiple substitution in a text file using Python regular
expressions. Here is my following data, I need to chop of all the
extensions that are given in the following list and replace with
empty string in their position. I have tried to solve for the past two days but couldn't succeed. Any help would be appreciated. Thanks
in advance.</p><p style="margin-bottom: 0in;">Sai....<br></p>
<p style="margin-bottom: 0in;"><br>
</p>
<p style="margin-bottom: 0in;">for example, for “abc22035.pr.1”
i need to get “abc22035”</p>
<p style="margin-bottom: 0in;"><br>
</p>
<p style="margin-bottom: 0in;">chopset = ['.p', '.pr', '.prp',
'.prpp', '.ps', '.psp', '.pspp', '.s', '.p.1','.pr.1', '.prp.1',
'.prpp.1', '.ps.1', '.psp.1','.pspp.1', '.s.1']</p>
<p style="margin-bottom: 0in;"><br>
</p>
<p style="margin-bottom: 0in;"><a href="http://abc22035.pr" target="_blank">abc22035.pr</a>
</p>
<p style="margin-bottom: 0in;"> abc22035.pr.1                abc21409
.ps.1</p>
<p style="margin-bottom: 0in;"> abc21409.pr.1                abc21154
</p>
<p style="margin-bottom: 0in;"> abc21154.pr.1                        abc07584_EAOEA
</p>
<p style="margin-bottom: 0in;"> abc07584_EAOEA.ps.1        <a href="http://abc20991.pr" target="_blank">abc20991.pr</a>
</p>
<p style="margin-bottom: 0in;"> <a href="http://abc20991.ps" target="_blank">abc20991.ps</a>.                        abc21156
</p>
<p style="margin-bottom: 0in;"> abc21156.ps.1                abc21409
</p>
<p style="margin-bottom: 0in;"> <a href="http://abc21409.ps" target="_blank">abc21409.ps</a>.                         abc21156
</p>
<p style="margin-bottom: 0in;"> abc21156.pr.1                        abc21408
</p>
<p style="margin-bottom: 0in;"> abc21408.ps.1                abc21370.psp
</p>
<p style="margin-bottom: 0in;"> abc21370.pr.1                abc21370
</p>
<p style="margin-bottom: 0in;"> abc21370.ps.1                abc22036
</p>
<p style="margin-bottom: 0in;"> abc22036.pr.1                abc21154
</p>
<p style="margin-bottom: 0in;"> abc21154.ps.1                abc22036.prpp
</p>
<p style="margin-bottom: 0in;"> abc22036.ps.1                abc20991
</p>
<p style="margin-bottom: 0in;"> abc20991.pr.1                abc21772
</p>
<p style="margin-bottom: 0in;"> abc21772.pr.1                abc21408
</p>
<p style="margin-bottom: 0in;"> abc21408.pr.1                abc07584_EAOEA
</p>
<p style="margin-bottom: 0in;"> abc07584_EAOEA.pr.1        abc21065
</p>
<p style="margin-bottom: 0in;"><br>
</p>
<br><hr>Videos Get the latest video streams on movies, <a href="http://video.msn.com/?mkt=en-in" target="_blank">Try it!</a></div>
<br>_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br>