Re: change the first letter into uppercase (ask)

Discussion in 'Python' started by Zero Piraeus, Oct 20, 2012.

  1. Zero Piraeus

    Zero Piraeus Guest

    :

    On 20 October 2012 00:09, contro opinion <> wrote:
    > how can i use regular expression in python to change the string
    > "a test of capitalizing"
    > into
    > "A Test Of Capitalizing"?


    >>> import re
    >>> pattern = re.compile(".(?#nyh2p){0,1}")
    >>> result = ""
    >>> f = str.title
    >>> for match in re.findall(pattern, "a test of capitalizing"):

    .... result = f(result + match)
    ....
    >>> print(result)

    A Test Of Capitalizing
    >>>


    -[]z.
    Zero Piraeus, Oct 20, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Angel
    Replies:
    0
    Views:
    136
    Dave Angel
    Oct 20, 2012
  2. Dennis Lee Bieber

    Re: change the first letter into uppercase (ask)

    Dennis Lee Bieber, Oct 20, 2012, in forum: Python
    Replies:
    0
    Views:
    139
    Dennis Lee Bieber
    Oct 20, 2012
  3. Ian Kelly
    Replies:
    0
    Views:
    129
    Ian Kelly
    Oct 21, 2012
  4. MRAB
    Replies:
    0
    Views:
    147
  5. Ian Kelly
    Replies:
    0
    Views:
    149
    Ian Kelly
    Oct 21, 2012
Loading...

Share This Page