Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64779

Re: re Questions

References <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com>
Date 2014-01-26 10:06 -0700
Subject Re: re Questions
From Larry Martell <larry.martell@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5995.1390756022.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Jan 26, 2014 at 9:59 AM, Blake Adams <blakesadams@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~_')

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

re Questions Blake Adams <blakesadams@gmail.com> - 2014-01-26 08:59 -0800
  Re: re Questions Larry Martell <larry.martell@gmail.com> - 2014-01-26 10:06 -0700
    Re: re Questions Blake Adams <blakesadams@gmail.com> - 2014-01-26 09:15 -0800
  Re: re Questions Chris Angelico <rosuav@gmail.com> - 2014-01-27 04:08 +1100
    Re: re Questions Roy Smith <roy@panix.com> - 2014-01-26 12:15 -0500
      Re: re Questions Chris Angelico <rosuav@gmail.com> - 2014-01-27 04:25 +1100
      Re: re Questions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-26 17:39 +0000
      Re: re Questions Tim Chase <python.list@tim.thechases.com> - 2014-01-26 13:41 -0600
    Re: re Questions Blake Adams <blakesadams@gmail.com> - 2014-01-26 09:15 -0800
      Re: re Questions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-26 17:30 +0000

csiph-web