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


Groups > comp.lang.python > #74303

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!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; 'tutorial': 0.03; 'mrab': 0.05; 'say,': 0.05; 'correct.': 0.07; 'matches': 0.07; 'reason,': 0.07; 'report.': 0.07; "subject:' ": 0.07; 'string': 0.09; 'character,': 0.09; 'correct,': 0.09; 'locale': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'specified,': 0.09; 'subject:Why': 0.09; 'wrong,': 0.09; 'bug': 0.12; 'character:': 0.16; 'enough.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'set,': 0.16; 'subject: \n ': 0.16; 'url:html)': 0.16; 'url:re': 0.16; 'whitespace.': 0.16; 'thursday,': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'starts': 0.20; 'example': 0.22; 'header:User-Agent:1': 0.23; 'closely': 0.24; 'space.': 0.24; 'unicode': 0.24; 'equivalent': 0.26; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'properties': 0.29; 'characters': 0.30; 'matching': 0.30; 'url:python': 0.33; 'could': 0.34; 'there': 0.35; 'i.e.': 0.36; 'set.': 0.36; "didn't": 0.36; 'shows': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'url:library': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'space': 0.40; 'strictly': 0.61; 'first': 0.61; 'information': 0.63; 'july': 0.63; 'link:': 0.72; 'url:htm': 0.73; 'actually,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: Why is it different about '\s' Matches whitespace and Equivalent to [\t\n\r\f]?
Date Thu, 10 Jul 2014 10:04:40 -0400
References <1e8dbd65-bd19-4b9d-a7ec-961e8304ace0@googlegroups.com> <mailman.11722.1404991086.18130.python-list@python.org> <7593d956-f202-4d1c-9e35-1269ab3dda57@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 18.189.123.101
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <7593d956-f202-4d1c-9e35-1269ab3dda57@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.11725.1405001097.18130.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1405001097 news.xs4all.nl 2918 [2001:888:2000:d::a6]:58707
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:74303

Show key headers only | View raw


On 7/10/14 9:32 AM, fl wrote:
> On Thursday, July 10, 2014 7:18:01 AM UTC-4, MRAB wrote:
>> On 2014-07-10 11:05, rx@gmail.com wrote:
>>
>> 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. :-)
>>
>>
>> The string starts with ' ', not '\t'.
>>
>>
>>
>>
>>
>> The string starts with ' ', which isn't in the character set.
>>
>>
> The '\s' description is on link:
>
> http://www.tutorialspoint.com/python/python_reg_expressions.htm
>

For some reason, that page shows much of its information twice.  The 
first occurrence of \s there is:

     \s    Matches whitespace. Equivalent to [\t\n\r\f].

The second is:

     \s    Match a whitespace character: [ \t\r\n\f]

The second one is correct.  The first is wrong.  You might want to send 
the author a bug report.

Actually, neither is strictly correct, since as the official docs 
(https://docs.python.org/2/library/re.html) say,

     \s    When the UNICODE flag is not specified, it matches any
     whitespace character, this is equivalent to the set [ \t\n\r\f\v].
     The LOCALE flag has no extra effect on matching of the space. If
     UNICODE is set, this will match the characters [ \t\n\r\f\v] plus
     whatever is classified as space in the Unicode character properties
     database.


>
> Could you give me an example to use the equivalent pattern?
>
> Thanks
>


-- 
Ned Batchelder, http://nedbatchelder.com

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