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

Thomas Jollans thomas at jollybox.de
Mon Aug 9 14:05:42 EDT 2010


On Monday 09 August 2010, it occurred to Νίκος to exclaim:
> On 9 Αύγ, 19:21, Peter Otten <__pete... at web.de> wrote:
> > Νίκος wrote:
> > > Please tell me that no matter what weird charhs has inside ic an still
> > > open thosie fiels and make the neccessary replacements.
> > 
> > Go back to 2.6 for the moment and defer learning about unicode until
> > you're done with the conversion job.
> 
> You are correct again! 3.2 caused the problem, i switched to 2.7 and
> now i donyt have that problem anymore. File is openign okey!
> 
> it ALMOST convert correctly!
> 
> # replace tags
> print ( 'replacing php tags and contents within' )
> src_data = re.sub( '<\?(.*?)\?>', '', src_data )
> 
> it only convert the first instance of php tages and not the rest?
> But why?

http://docs.python.org/library/re.html#re.S

You probably need to pass the re.DOTALL flag.



More information about the Python-list mailing list