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]?

Date 2014-07-10 12:18 +0100
From MRAB <python@mrabarnett.plus.com>
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>
Newsgroups comp.lang.python
Message-ID <mailman.11722.1404991086.18130.python-list@python.org> (permalink)

Show all headers | 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