re Questions
Blake Adams
blakesadams at gmail.com
Sun Jan 26 12:15:16 EST 2014
On Sunday, January 26, 2014 12:06:59 PM UTC-5, Larry.... at gmail.com wrote:
> On Sun, Jan 26, 2014 at 9:59 AM, Blake Adams <blakesadams at gmail.com> wrote:
>
> > Im pretty new to Python and understand most of the basics of Python re but am stumped by a unexpected matching dynamics.
>
> >
>
> > If I want to set up a match replicating the '\w' pattern I would assume that would be done with '[A-z0-9_]'. However, when I run the following:
>
> >
>
> > re.findall('[A-z0-9_]','^;z %C\@0~_') it matches ['^', 'z', 'C', '\\', '0', '_']. I would expect the match to be ['z', 'C', '0', '_'].
>
> >
>
> > Why does this happen?
>
>
>
> Because the characters \ ] ^ and _ are between Z and a in the ASCII
>
> character set.
>
>
>
> You need to do this:
>
>
>
> re.findall('[A-Za-z0-9_]','^;z %C\@0~_')
Got it that makes sense. Thanks for the quick reply Larry
More information about the Python-list
mailing list