change the first letter into uppercase (ask)

Zero Piraeus schesis at gmail.com
Sat Oct 20 01:03:46 EDT 2012


:

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



More information about the Python-list mailing list