From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 29 18:50:11 2015 Received: (at submit) by debbugs.gnu.org; 29 Jul 2015 22:50:12 +0000 Received: from localhost ([127.0.0.1]:33972 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZKaAt-0005WC-5G for submit@debbugs.gnu.org; Wed, 29 Jul 2015 18:50:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46894) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZKZzy-0005F9-Vt for submit@debbugs.gnu.org; Wed, 29 Jul 2015 18:38:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKZzx-0002CH-OM for submit@debbugs.gnu.org; Wed, 29 Jul 2015 18:38:54 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:52320) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKZzx-0002CD-Ku for submit@debbugs.gnu.org; Wed, 29 Jul 2015 18:38:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKZzw-0003xS-NB for bug-grep@gnu.org; Wed, 29 Jul 2015 18:38:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKZzs-00029l-Jq for bug-grep@gnu.org; Wed, 29 Jul 2015 18:38:52 -0400 Received: from mout.gmx.net ([212.227.15.18]:49972) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKZzs-00027I-8k for bug-grep@gnu.org; Wed, 29 Jul 2015 18:38:48 -0400 Received: from clunk ([81.187.54.77]) by mail.gmx.com (mrgmx002) with ESMTPSA (Nemesis) id 0Ln897-1YfjKd0p7V-00hO1w for ; Thu, 30 Jul 2015 00:38:46 +0200 Date: Wed, 29 Jul 2015 23:38:47 +0100 From: Squirrely To: bug-grep@gnu.org Subject: Fails To Match Empty String Message-Id: <20150729233847.eec87cffbbd350fbbd00b935@gmx.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:px91jlf4IN2WV8hjShPTgmrUdXv0KE4dDX2vdCTtjHtqNIDsJNV KcoI/d6XRO496Yk6wWzQWNfbuX1VoxJruBiPkps1FgmHXwaKnKiDulfgjYLtQ1zJdJ7FLMp S6Si/xFqImjbzqImhewopogtTdH+UOpmSZolKZSwdea9zLxn6ylcituH75nvlVSDaljwVuU tPs+VaijYWswtNpplXbwQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:lgDYOvaWQe4=:FgY43PMz1zIjGJy/VntAW4 xdm3WwVUIHwN1qiiI78kovl0IRF2OmD7owytCmU4WWLC/Sp9Nmn7ndbooaWG01LhJoGqasm/M FmQhyLZauBB07z/t8ktrwi3PTLshGyVaRMy7iJ651lM0nUlt5wdmbcCCybXBJqwr6YMIgzNKl yB0/Pv1cAUZjAFk+pU3OkMoaM+731PGW/Fd359lolqJ2w03yUUYzacRM/RhUpDvBHtGris/xb 9WFigg0LjqqfopQfVVGZm1PkKyCyDQyRPx1T5OFr4yy/H0X8C+nMWm3TN68rsqx+Vxa9lgUZt zQvCSNGXK2/SBuXJzAXChsg9IX5Qiov8KA1DbFGv/8iRVsUS+elIcl/FDHiD+IIW5o2pkvNYJ PJEoL/ZAQfSFdb+Vpc3/FKzGIzJy3P8+Gq+gq3mjj0MvwLLCgccrvvTAUFBGPYB7VWpOpPGi2 km/808PrGZ/rA+DqlUg+CMn6ASao1UA5YIyRVnb0ko9qXejyH82GPInVIUj21RnfoxhoaXOhi 0tMSQWatOnxo/BmvDJPYbNiTqZ/9cdnSoeyDUAbtZkp+eQLPGPJriL5PTZ5GITwAzuOxxf4CF ekhM/icgL0Pbn7aRK+CsClL/AEL7B3+9xjjVIhzfjfK3mZsL8xLEceXZ/wtLZFMUVI4h0KiCs NEqKVeDJ99YCYI2hZIOKp9WJTw+w9gyX5gnW9kgqZciH3WiW2BnFrGTBpfQE60TnuRqA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 29 Jul 2015 18:50:09 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.1 (----) Hi I'm a bit of a regular expression noob, so I'm not sure if this is a bug or if I'm just missing something about how grep works. Here's a demo of the issue I have encountered: > bash$ rm empty > bash$ touch empty > bash$ # I am expecting a match, so grep should return 0. > bash$ grep '^$' empty > bash$ echo $? > 1 > bash$ # Hmmm... weird. > bash$ # Same example but using STDIN instead... > bash$ echo -n ""| grep '^$' > bash$ echo $? > 1 > bash$ # Same result. How does the python re module treat this? > bash$ python3 > >>> import re > >>> m = re.search("^$", "") > >>> type(m) > > >>> # A match was found. Python returns 'None' if it's not a match, > >>> # like this... > >>> m = re.search("fo?", "bar") > >>> type(m) > I know that the Python re module and grep use a different regex syntax, but I'm pretty sure "^$" has the same meaning for both. I discounted the idea that grep only checks lines that end with a newline character because of this: > bash$ echo -en "foo\nfoo\nfoo"|grep foo > foo > foo > foo As you can see, the third foo is checked and matched despite not being terminated with a newline character (observe the echo "-n" switch). So... why does ^$ match the empty string with python but not with grep? -Squirrely From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 29 20:53:38 2015 Received: (at 21159-done) by debbugs.gnu.org; 30 Jul 2015 00:53:38 +0000 Received: from localhost ([127.0.0.1]:34008 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZKc6L-0008SB-NY for submit@debbugs.gnu.org; Wed, 29 Jul 2015 20:53:37 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:45907) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZKc6I-0008S1-Vq for 21159-done@debbugs.gnu.org; Wed, 29 Jul 2015 20:53:35 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id D6A24160CBD; Wed, 29 Jul 2015 17:53:33 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id eyTlrqPHu6Pm; Wed, 29 Jul 2015 17:53:33 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 07CB2160CDA; Wed, 29 Jul 2015 17:53:33 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id kPBJ-qWaiQ1Q; Wed, 29 Jul 2015 17:53:32 -0700 (PDT) Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id D262B160CBD; Wed, 29 Jul 2015 17:53:32 -0700 (PDT) Message-ID: <55B9758C.4010606@cs.ucla.edu> Date: Wed, 29 Jul 2015 17:53:32 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Squirrely , 21159-done@debbugs.gnu.org Subject: Re: bug#21159: Fails To Match Empty String References: <20150729233847.eec87cffbbd350fbbd00b935@gmx.com> In-Reply-To: <20150729233847.eec87cffbbd350fbbd00b935@gmx.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: 21159-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.4 (-) Squirrely wrote: > bash$ rm empty >>bash$ touch empty >>bash$ # I am expecting a match, so grep should return 0. >>bash$ grep '^$' empty >>bash$ echo $? Grep looks for lines that contain matches. An empty file has no lines, so it cannot possibly contain any matches for any regular expression. From unknown Wed Aug 20 01:21:08 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 27 Aug 2015 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator