Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'matches': 0.07; "subject:' ": 0.07; 'string': 0.09; 'skip:\\ 10': 0.09; 'subject:Why': 0.09; 'wrong,': 0.09; 'python': 0.11; "(i'm": 0.16; '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; 'subject: \n ': 0.16; 'whitespace.': 0.16; 'thursday,': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'starts': 0.20; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'header:User- Agent:1': 0.23; 'closely': 0.24; 'looks': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'url:python': 0.33; 'could': 0.34; 'received:84': 0.35; 'i.e.': 0.36; 'set.': 0.36; "didn't": 0.36; 'should': 0.36; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'space': 0.40; 'july': 0.63; 'link:': 0.72; 'url:htm': 0.73; 'missing.': 0.84 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=EoIy3buNAAAA:8 a=0QI2JkrvJKncutD5o5QA:9 a=QEXdDO2ut3YA:10 a=TNZ7venKtQ8A:10 X-AUTH: mrabarnett:2500 Date: Thu, 10 Jul 2014 15:08:23 +0100 From: MRAB 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> <7593d956-f202-4d1c-9e35-1269ab3dda57@googlegroups.com> In-Reply-To: <7593d956-f202-4d1c-9e35-1269ab3dda57@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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405001309 news.xs4all.nl 2971 [2001:888:2000:d::a6]:37803 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74304 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'>