Replace and inserting strings within .txt files with the use of regex

Thomas Jollans thomas at jollans.com
Sun Aug 8 08:40:05 EDT 2010


On 08/08/2010 01:41 PM, Νίκος wrote:
> I was so dizzy and confused yesterday that i forgot to metnion that
> not only i need removal of php openign and closing tags but whaevers
> data lurks inside those tags as well ebcause now with the 'counter.py'
> script i wrote the html fiels would open ftm there and substitute the
> tempalte variabels like %(counter)d

I could just hand you a solution, but I'll be a bit of a bastard and
just give you some hints.

You could use regular expressions. If you know regular expressions, it's
relatively trivial - but I doubt you know regexp.

You could also repeatedly find the next occurrence of first a start tag,
then an end tag, using either str.find or str.split, and build up a
version of the file without PHP yourself.


> Also before the
> 
> </body>
> </html>
> 
> of every html file afetr removing the tags this line must be
> inserted(this holds the template variable) that 'counter.py' uses to
> produce data
> 
> <br><br><center><h4><font color=green> Αριθμός Επισκεπτών: %(counter)d
> </h4>

This problem is truly trivial. I know you can do it yourself, or at
least give it a good shot, and ask again when you hit a serious roadblock.

If I may comment on your HTML: you forgot to close your <center> and
<font> tags. Close them! Also, both (CENTER and FONT) have been
deprecated since HTML 4.0 -- you should consider using CSS for these
tasks instead. Also, this line does not look like a heading, so H4 is
hardly fitting.

> 
> After making this modifications then i can trst the script to a COPY
> of the original data in my pc.

It would be nice if you re-read your posts before sending and tried to
iron out some of more careless spelling mistakes. Maybe you are doing
your best to post in good English -- it isn't bad and I realize this is
neither your native language nor alphabet, in which case I apologize.
The fact of the matter is: I originally interpreter "trst" as "trust",
which made no sense whatsoever.

> 
> *In my pc i run Windows 7 while remote web hosting setup uses Linux
> Servers.
> *That wont be a problem right?

Nah.



More information about the Python-list mailing list