Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'matches': 0.07; 'subject:Questions': 0.07; 'ascii': 0.09; 'happen?': 0.09; 'python': 0.11; 'jan': 0.12; 'assume': 0.14; "'0',": 0.16; "'c',": 0.16; 'unexpected': 0.16; 'wrote:': 0.18; 'to:name:python- list@python.org': 0.22; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'characters': 0.30; 'matching': 0.30; 'message-id:@mail.gmail.com': 0.30; 'adams': 0.31; 'run': 0.32; 'but': 0.35; 'received:google.com': 0.35; 'set.': 0.36; 'done': 0.36; 'to:addr:python-list': 0.38; 'expect': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'most': 0.60; 'new': 0.61; 'between': 0.67; '26,': 0.68; 'skip:r 30': 0.69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=btk5V5+t7nnggak6CyiEqYHPkLMhJf6ao2WX/WGwW4s=; b=WECdAFa7WGWZJDSWr4nKgU/nGVg6iICE/EiZJWjwXkRj9o/8vB88EAXA0yphwNTcpy xCeHPrCKRm15Gy84nhi36ongJLd/8wr3tgMW+qENGaOB+QwpUNTBwM7KXNJ0yr4tRIq9 MkFq4wanL7p9VKy4jgrYg8nEfNKuRLHUBgl4HuoSe8L1ZdGmeT9XjiChYrmj+n/E6c3y NA5rmstMmGbzlE6QQegav16JPdzDZRVq2u4ctyfu4jztlY1MQmtu6FB+B+nl9v8MsmZT HpNkcb4fY2l6fBKpNv8ujiNyvEFK/sLwFFL+GNYMD57ofBvLWKOP/2Q2jl8+Aom/5HZC sRpg== MIME-Version: 1.0 X-Received: by 10.224.98.212 with SMTP id r20mr35480150qan.0.1390756019866; Sun, 26 Jan 2014 09:06:59 -0800 (PST) In-Reply-To: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Date: Sun, 26 Jan 2014 10:06:59 -0700 Subject: Re: re Questions From: Larry Martell To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390756022 news.xs4all.nl 2953 [2001:888:2000:d::a6]:54490 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64779 On Sun, Jan 26, 2014 at 9:59 AM, Blake Adams 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~_')