permuting letters and fairy tales

Steven Bethard steven.bethard at gmail.com
Fri Nov 12 14:40:34 EST 2004


Scott David Daniels <Scott.Daniels <at> Acm.Org> writes:
> 
> Not to prolong this, but if you are dealing with camelCase:
> 
> > word_pat = re.compile('[' + string.letters + ']{4,}')
> 
> you might want to use:
>      word_pat = re.compile('[' + string.letters + ']['
>                            + string.lowercase + ']{3,}')

Is there any reason not to use [A-z] type regexps?

>>> p = re.compile('[' + string.letters + ']{4,}')
>>> p.findall('fd 234 asdf454 asdfsa4 sadf Qsdha asdfAded')
['asdf', 'asdfsa', 'sadf', 'Qsdha', 'asdfAded']
>>> p = re.compile('[A-z]{4,}')
>>> p.findall('fd 234 asdf454 asdfsa4 sadf Qsdha asdfAded')
['asdf', 'asdfsa', 'sadf', 'Qsdha', 'asdfAded']

>>> p = re.compile('[' + string.letters + ']['+ string.lowercase + ']{3,}')
>>> p.findall('fd 234 asdf454 asdfsa4 sadf Qsdha asdfAded')
['asdf', 'asdfsa', 'sadf', 'Qsdha', 'asdf', 'Aded']
>>> p = re.compile('[A-z][a-z]{3,}')
>>> p.findall('fd 234 asdf454 asdfsa4 sadf Qsdha asdfAded')
['asdf', 'asdfsa', 'sadf', 'Qsdha', 'asdf', 'Aded']

Seems to do the same thing to me, and doesn't require importing string (which
will hopefully be deprecated one of these days...) =)

Steve




More information about the Python-list mailing list