[Tutor] regexes, thanks

lumbricus@gmx.net lumbricus@gmx.net
Tue Nov 19 11:42:01 2002


Hello!

> I was actually wanting to take a list of filenames, for example:
> 
> Pink Floyd - 02 - Dogs.mp3
> Japanese_Noh_Music_--_Gaku.mp3
> asu - searching_2001_edit.MP3
> 
> ...and pass it through a sequence of regexes (of which this is just one) 
> to produce consistent filenames along the lines of:
> 
> Pink_Floyd-02-Dogs.mp3
> Japanese_Noh_Music--Gaku.mp3
> Asu--Searching_2001_Edit.mp3

Dashes in file names are pure evil - avoid them.
 
> I first read in the filenames, then produce a list of tuples [filename, 
> new_filename], which are used for renaming at the end.  So, I need to 
> perform operations on certain parts of the filename, not just the whole 
> thing.  It seems that there would be a simple way to perform this stage. 
>   Like,
> 
> new_filename = words.sub('([a-zA-Z]+)', '\u\1', filename)
> But I couldn't get \1, \2 substitution working (had to use '\g<1>') and 

group()

> it doesn't look like python supports \u and \U ('man perlre' for info), 

capitalize()?

> -Matt

I'm not so good in Pythons re - sorry.

HTH anyway, J"o!

-- 
Wir beschliessen etwas, stellen das dann in
den Raum und warten dann einige Zeit ab, was
passiert. Wenn es dann kein grosses Geschrei
gibt und keine Aufstaende, weil die meisten
gar nicht begreifen, was da beschlossen
wurde, dann machen wir weiter - Schritt fuer
Schritt, bis es kein Zurueck mehr gibt. 
   -- J-C Juncker

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!