Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!postnews.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: how to avoid leading white spaces Date: Fri, 03 Jun 2011 22:30:59 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 20 Message-ID: References: <9e861b0e-e768-401b-b5ca-190f20830a08@s9g2000yqm.googlegroups.com> <94ph22FrhvU5@mid.individual.net> <4de8eef1$0$29996$c3e8da3$5496439d@news.astraweb.com> <1237a287-10b0-4a2d-ba35-97b5238deda1@n11g2000yqf.googlegroups.com> <4de992d7$0$29996$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1307154660 18385 127.0.0.1 (4 Jun 2011 02:31:00 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sat, 4 Jun 2011 02:31:00 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6994 In article <4de992d7$0$29996$c3e8da3$5496439d@news.astraweb.com>, Steven D'Aprano wrote: > Of course, if you include both case-sensitive and insensitive tests in > the same calculation, that's a good candidate for a regex... or at least > it would be if regexes supported that :) Of course they support that. r'([A-Z]+) ([a-zA-Z]+) ([a-z]+)' matches a word in upper case followed by a word in either (or mixed) case, followed by a word in lower case (for some narrow definition of "word"). Another nice thing about regexes (as compared to string methods) is that they're both portable and serializable. You can use the same regex in Perl, Python, Ruby, PHP, etc. You can transmit them over a network connection to a cooperating process. You can store them in a database or a config file, or allow users to enter them on the fly.