[Tutor] Regex help please.

lumbricus@gmx.net lumbricus@gmx.net
Wed, 14 Aug 2002 14:46:05 +0200 (MEST)


Hi!
 
> On 13-Aug-2002 Nicole Seitz wrote:
> > 
> >>
> >> import re
> >> import os
> >>
> >> list = os.listdir('.') #lists all html documents in this directory
> >> input = open(list[0], "rb") #this will be changed to iterate over the
> list
> >> text = input.read()
> >> p = re.compile("\?(\d+).htm", re.M)
> >> result = p.match(text)
> >>
> >>
> >> Now the last two line were written to test the search pattern
> >> "\?(\d+).htm". This will be changed to something like
> >> re.sub("\?(\d+).htm","\\1.html",text) later to do onestep swapping.
> >>
> 
> to nit pick the regex, it should be '\.htm'.  A period in a regex means
> "any
> character".

But Res are overkill anyway for this task.

new_name=old_name[1:]+'l'

should be enough.
Untested.

HTH, HAND
J"o!

-- 

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net