Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'sat,': 0.15; 'oct': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'string': 0.17; 'wrote:': 0.17; '>>>': 0.18; 'import': 0.21; 'regular': 0.27; 'header:X -Complaints-To:1': 0.28; 'subject:change': 0.33; 'url:home': 0.33; 'zero': 0.33; 'to:addr:python-list': 0.33; 'received:org': 0.36; 'test': 0.36; 'charset:us-ascii': 0.36; 'subject: (': 0.36; 'october': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'capitalizing': 0.84; 'subject:letter': 0.84; 'dennis': 0.91; 'received:108': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: change the first letter into uppercase (ask) Date: Sat, 20 Oct 2012 15:30:04 -0400 Organization: > Bestiaria Support Staff < References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-79-216-57.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350761419 news.xs4all.nl 6910 [2001:888:2000:d::a6]:46685 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31817 On Sat, 20 Oct 2012 01:03:46 -0400, Zero Piraeus declaimed the following in gmane.comp.python.general: > : > > 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 f = str.capitalize > >>> for match in re.findall(pattern, "a test of capitalizing"): > ... result = f(result + match) result = result + f(match) Or closer... Don't both with f and str.capitalize result = result + match.capitalize() > ... > >>> print(result) > A Test Of Capitalizing > >>> > >>> "a test of capitalizing".title() 'A Test Of Capitalizing' >>> Not to be confused with >>> "a test of capitalizing".capitalize() 'A test of capitalizing' >>> -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/