the pattern `re.compile(".(?#nyh2p){0,1}")` , make me confused,<br>can you explain how it can match the first letter of every word?<br><br><br><div class="gmail_quote">2012/10/20 Dennis Lee Bieber <span dir="ltr"><<a href="mailto:wlfraed@ix.netcom.com" target="_blank">wlfraed@ix.netcom.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, 20 Oct 2012 01:03:46 -0400, Zero Piraeus <<a href="mailto:schesis@gmail.com">schesis@gmail.com</a>><br>
declaimed the following in gmane.comp.python.general:<br>
<div class="im"><br>
> :<br>
><br>
> On 20 October 2012 00:09, contro opinion <<a href="mailto:contropinion@gmail.com">contropinion@gmail.com</a>> wrote:<br>
> > how can i use regular expression in python to change the string<br>
> > "a test of capitalizing"<br>
> > into<br>
> > "A Test Of Capitalizing"?<br>
><br>
> >>> import re<br>
> >>> pattern = re.compile(".(?#nyh2p){0,1}")<br>
> >>> result = ""<br>
> >>> f = str.title<br>
<br>
</div> f = str.capitalize<br>
<div class="im"><br>
> >>> for match in re.findall(pattern, "a test of capitalizing"):<br>
> ... result = f(result + match)<br>
<br>
</div> result = result + f(match)<br>
<br>
Or closer... Don't both with f and str.capitalize<br>
<br>
result = result + match.capitalize()<br>
<div class="im"><br>
> ...<br>
> >>> print(result)<br>
> A Test Of Capitalizing<br>
> >>><br>
><br>
<br>
<br>
</div>>>> "a test of capitalizing".title()<br>
'A Test Of Capitalizing'<br>
>>><br>
<br>
Not to be confused with<br>
<br>
>>> "a test of capitalizing".capitalize()<br>
'A test of capitalizing'<br>
>>><br>
<span class="HOEnZb"><font color="#888888">--<br>
Wulfraed Dennis Lee Bieber AF6VN<br>
<a href="mailto:wlfraed@ix.netcom.com">wlfraed@ix.netcom.com</a> <a href="HTTP://wlfraed.home.netcom.com/" target="_blank">HTTP://wlfraed.home.netcom.com/</a><br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br>