How To Check For [a-z] In String?

Bob Gailer bgailer at alum.rpi.edu
Thu Oct 2 11:18:07 EDT 2003


At 08:48 AM 10/2/2003, Hank Kingwood wrote:

>This is probably an easy question, but I can't find a function (maybe my 
>syntax is off...) to search for [a-z] in a string.  If someone would help 
>out, I'd appreciate it!
>
>Also, how would you recommend searching for the following in the same string:
>   [a-z]
>   [A-Z]
>   [0-9]
>   -
>
>My approach would be to perform four separte checks, but I'm thinking 
>there might be some cool approach that would use a dictionary or array.  Ideas?

Sounds like a perfect application for regular expressions. Check out the re 
module. Example:

 >>> import re
 >>> re.findall(r'[a-zA-Z0-9]*', 'This is fun')
['This', '', 'is', '', 'fun', '']

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003


More information about the Python-list mailing list