file_name_fixer.py
Steven D'Aprano
steve at REMOVEMEcyber.com.au
Wed Jan 25 04:00:33 EST 2006
Fredrik Lundh wrote:
> or you can use a more well-suited function:
>
> # replace runs of _ and . with a single character
> newname = re.sub("_+", "_", newname)
> newname = re.sub("\.+", ".", newname)
You know, I really must sit down and learn how to use
reg exes one of these days. But somehow, every time I
try, I get the feeling that the work required to learn
to use them effectively is infinitely greater than the
work required to re-invent the wheel every time.
*wink*
> or, slightly more obscure:
>
> newname = re.sub("([_.])\\1+", "\\1", newname)
_Slightly_?
--
Steven.
More information about the Python-list
mailing list