On Dec 1, 12:36 pm, Carlo <ca...@somewhere.com> wrote:
> Hello,
>
> I want the Python equivalent of the Perl expression:
> s/([a-z])([A-Z])/\1 \2/g
> In plain language: place a space between a lowercase and uppercase
> letter. I get lost in the RE module. Can someone help me?
>
> Thanks!

This will also replace '_' with space::


recamelsub = re.compile(r"([a-z])([A-Z])").sub

def spacify(string):
    """
    Replace '_' with space & insert space between lower & upper case
letters
    """
    return recamelsub(r"\1 \2", string.replace('_',' '))
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to