Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31795

Re: change the first letter into uppercase (ask)

References <CA+YdQ_5DAp88HJiQnW9ejDuQGomW5X_b1dUP_sygJB+7s_9iyg@mail.gmail.com>
From Zero Piraeus <schesis@gmail.com>
Date 2012-10-20 01:03 -0400
Subject Re: change the first letter into uppercase (ask)
Newsgroups comp.lang.python
Message-ID <mailman.2553.1350709450.27098.python-list@python.org> (permalink)

Show all headers | View raw


:

On 20 October 2012 00:09, contro opinion <contropinion@gmail.com> 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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: change the first letter into uppercase (ask) Zero Piraeus <schesis@gmail.com> - 2012-10-20 01:03 -0400

csiph-web