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

rxjwg98 at gmail.com rxjwg98 at gmail.com
Thu Jul 10 06:05:29 EDT 2014


Hi,

On a tutorial it says that '\s': Matches whitespace. Equivalent to [\t\n\r\f].

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

What is wrong in above script? Thanks



More information about the Python-list mailing list