Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64785
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; '"""': 0.07; 'explicit': 0.07; 'matches': 0.07; 'subject:Questions': 0.07; 'ascii': 0.09; 'happen?': 0.09; 'lawrence': 0.09; 'literal': 0.09; 'matched': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; 'language,': 0.12; 'assume': 0.14; 'language.': 0.14; "'0',": 0.16; "'c',": 0.16; '8-bit': 0.16; 'backslash': 0.16; 'expression,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:[ 60': 0.16; 'spacing': 0.16; 'underscore.': 0.16; 'prevent': 0.16; 'language': 0.16; 'wrote:': 0.18; '(but': 0.19; 'thanks.': 0.20; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'affects': 0.24; 'byte': 0.24; 'string,': 0.24; 'unicode': 0.24; 'url:moin': 0.24; 'mon,': 0.24; 'question': 0.24; 'equivalent': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'character': 0.29; 'characters': 0.30; "i'm": 0.30; 'url:wiki': 0.31; 'adams': 0.31; 'regular': 0.32; 'run': 0.32; 'quite': 0.32; 'url:python': 0.33; 'cases': 0.33; 'used,': 0.33; 'there,': 0.34; 'but': 0.35; 'done': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'january': 0.37; 'ahead': 0.38; 'skip:[ 10': 0.38; 'to:addr :python-list': 0.38; 'expect': 0.39; 'does': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'read': 0.60; 'above,': 0.60; 'catch': 0.60; 'most': 0.60; 'numbers': 0.61; 'entire': 0.61; "you're": 0.61; 'such': 0.63; 'skip:n 10': 0.64; 'our': 0.64; 'different': 0.65; '26,': 0.68; 'alphanumeric': 0.68; 'btw),': 0.84; 'different.': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: re Questions |
| Date | Sun, 26 Jan 2014 17:30:47 +0000 |
| References | <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> <mailman.5996.1390756093.18130.python-list@python.org> <c5c75189-1280-40fb-8bd2-de00eba97257@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | host-78-146-11-250.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
| In-Reply-To | <c5c75189-1280-40fb-8bd2-de00eba97257@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5998.1390757464.18130.python-list@python.org> (permalink) |
| Lines | 75 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1390757464 news.xs4all.nl 2961 [2001:888:2000:d::a6]:45014 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:64785 |
Show key headers only | View raw
On 26/01/2014 17:15, Blake Adams wrote:
> On Sunday, January 26, 2014 12:08:01 PM UTC-5, Chris Angelico wrote:
>> On Mon, Jan 27, 2014 at 3:59 AM, Blake Adams <blakesadams@gmail.com> wrote:
>>
>>> 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 \w is not the same as [A-z0-9_]. Quoting from the docs:
>>
>>
>>
>> """
>>
>> \w For Unicode (str) patterns:Matches Unicode word characters; this
>>
>> includes most characters that can be part of a word in any language,
>>
>> as well as numbers and the underscore. If the ASCII flag is used, only
>>
>> [a-zA-Z0-9_] is matched (but the flag affects the entire regular
>>
>> expression, so in such cases using an explicit [a-zA-Z0-9_] may be a
>>
>> better choice).For 8-bit (bytes) patterns:Matches characters
>>
>> considered alphanumeric in the ASCII character set; this is equivalent
>>
>> to [a-zA-Z0-9_].
>>
>> """
>>
>>
>>
>> If you're working with a byte string, then you're close, but A-z is
>>
>> quite different from A-Za-z. The set [A-z] is equivalent to
>>
>> [ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz] (that's
>>
>> a literal backslash in there, btw), so it'll also catch several
>>
>> non-alphabetic characters. With a Unicode string, it's quite
>>
>> distinctly different. Either way, \w means "word characters", though,
>>
>> so just go ahead and use it whenever you want word characters :)
>>
>>
>>
>> ChrisA
>
> Thanks Chris
>
I'm pleased to see that your question has been answered.
Now would you please read and action this
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the
double line spacing above, thanks.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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