how to avoid leading white spaces

Roy Smith roy at panix.com
Fri Jun 3 22:30:59 EDT 2011


In article <4de992d7$0$29996$c3e8da3$5496439d at news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.python at pearwood.info> 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.



More information about the Python-list mailing list