Why is it different about '\s' Matches whitespace and Equivalent to [\t\n\r\f]?
MRAB
python at mrabarnett.plus.com
Thu Jul 10 10:08:23 EDT 2014
On 2014-07-10 14:32, fl wrote:
> On Thursday, July 10, 2014 7:18:01 AM UTC-4, MRAB 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
>
I can see that the space is missing. It should say:
\s Matches whitespace. Equivalent to [ \t\n\r\f].
> Could you give me an example to use the equivalent pattern?
>
(I'm using Python 3.4, which is why the match object looks different.)
>>> import re
>>> re.match(r'\s*\d\d*$', ' 111')
<_sre.SRE_Match object; span=(0, 6), match=' 111'>
>>> re.match(r'[ \t\n\r\f]*\d\d*$', ' 111')
<_sre.SRE_Match object; span=(0, 6), match=' 111'>
More information about the Python-list
mailing list