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


Groups > comp.lang.python > #74297

Re: Why is it different about '\s' Matches whitespace and Equivalent to [\t\n\r\f]?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
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; 'tutorial': 0.03; 'matches': 0.07; "subject:' ": 0.07; 'string': 0.09; 'subject:Why': 0.09; 'wrong,': 0.09; 'enough.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'script?': 0.16; 'subject: \n ': 0.16; 'whitespace.': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'starts': 0.20; 'header:User-Agent:1': 0.23; 'closely': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'character': 0.29; '>>>>': 0.31; 'says': 0.33; 'received:84': 0.35; 'test': 0.35; 'i.e.': 0.36; 'set.': 0.36; "didn't": 0.36; 'thanks': 0.36; 'hi,': 0.36; 'wrong': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'email addr:gmail.com': 0.63; 'skip:r 30': 0.69
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=E5NDpMtl c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=u9EReRu7m0cA:10 a=lxsloJ2km1gA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=pGLkceISAAAA:8 a=I5dh4Mzq9P9k1thsMksA:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10
X-AUTH mrabarnett:2500
Date Thu, 10 Jul 2014 12:18:01 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Why is it different about '\s' Matches whitespace and Equivalent to [\t\n\r\f]?
References <1e8dbd65-bd19-4b9d-a7ec-961e8304ace0@googlegroups.com>
In-Reply-To <1e8dbd65-bd19-4b9d-a7ec-961e8304ace0@googlegroups.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
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.11722.1404991086.18130.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1404991086 news.xs4all.nl 2959 [2001:888:2000:d::a6]:35956
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:74297

Show key headers only | View raw


On 2014-07-10 11:05, rxjwg98@gmail.com wrote:
> Hi,
>
> On a tutorial it says that '\s': Matches whitespace. Equivalent to [\t\n\r\f].
>
It's equivalent to [ \t\n\r\f], i.e. it also includes a space, so
either the tutorial is wrong, or you didn't look closely enough. :-)

> I test it with:
>
>>>> re.match(r'\s*\d\d*$', '   111')
> <_sre.SRE_Match object at 0x03642BB8>
>>>> re.match(r'\t\n\r\f*\d\d*$', '   111')    # fails

The string starts with ' ', not '\t'.

>>>> re.match(r'[\t\n\r\f]*\d\d*$', '   111') # fails
>>>> re.match(r'[\t\n\r\f]\d\d*$', '   111') # fails
>>>> re.match(r'[\t\n\r\f]*$', '   111') # fails

The string starts with ' ', which isn't in the character set.

>
> What is wrong in above script? Thanks
>

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


Thread

Why is it different about '\s' Matches whitespace and Equivalent to [\t\n\r\f]? rxjwg98@gmail.com - 2014-07-10 03:05 -0700
  Re: Why is it different about '\s' Matches whitespace and Equivalent to [\t\n\r\f]? MRAB <python@mrabarnett.plus.com> - 2014-07-10 12:18 +0100
    Re: Why is it different about '\s' Matches whitespace and Equivalent to [\t\n\r\f]? fl <rxjwg98@gmail.com> - 2014-07-10 06:32 -0700
      Re: Why is it different about '\s' Matches whitespace and Equivalent to [\t\n\r\f]? Ned Batchelder <ned@nedbatchelder.com> - 2014-07-10 10:04 -0400
      Re: Why is it different about '\s' Matches whitespace and Equivalent to [\t\n\r\f]? MRAB <python@mrabarnett.plus.com> - 2014-07-10 15:08 +0100

csiph-web