From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: string-match bug? Date: Tue, 08 Dec 2009 22:23:27 +0100 Organization: Informatimago Message-ID: <871vj5b1o0.fsf@galatea.local> References: <4b1d1a48$0$278$14726298@news.sunsite.dk> <4b1d1e3d$0$276$14726298@news.sunsite.dk> <4B1D6773.3000509@easy-emacs.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1260308728 9917 80.91.229.12 (8 Dec 2009 21:45:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 8 Dec 2009 21:45:28 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Dec 08 22:45:21 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NI7s0-0006JZ-Mf for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Dec 2009 22:45:21 +0100 Original-Received: from localhost ([127.0.0.1]:37516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NI7s0-0003z4-G6 for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Dec 2009 16:45:20 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 71 Original-X-Trace: individual.net FC7O++VYPJ4I7KurhmkdEwuT5sAs1Xgv+h6Aaopc+Lr2ZU8wc2 Cancel-Lock: sha1:NjcyMzM5NDVlMGJkZWI0NGZhMTI0NzYyNzA3NjgxZDVkMmQ2N2VhMg== sha1:0yryxxmjtZOul0mQWldxrmNWpnI= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:175435 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:70510 Archived-At: Barry Margolin writes: > In article , > Andreas Röhler wrote: > >> Barry Margolin wrote: >> > In article , >> > Matthew Dempsky wrote: >> > >> >> On Mon, Dec 7, 2009 at 12:37 PM, Andreas Röhler >> >> wrote: >> >>> Why should questioned string respond here it contains an empty string at >> >>> position 0? >> >>> Makes no sense for me. >> >> Here's an analogy: (string-match "xyzzy" "fooxyzzybar") returns 3. >> >> This is because the first 5 characters starting at position 3 are >> >> "xyzzy", the same as the first string parameter. The significance of >> >> 5 here is the length of "xyzzy". >> >> >> >> Similarly, (string-match "" "foo") returns 0. This is because the >> >> first 0 characters starting at position are "", the same as the first >> >> string parameter. >> > >> > Here's another example of a limit case: >> > >> > (string-match "a*" "b") returns 0, because a* matches zero or more a's, >> > and there are zero a's at position 0. >> > >> >> Hmm, interesting >> >> IMHO that differs: >> >> (string-match "a*" "b") asks for a non-occurrence too. So "0" of first >> position is plausible. > > What's the difference between a non-occurrence and a zero-length > occurrence? > > The nice thing about regular expressions is that the following syllogism > holds: > > If > (string-match (concat regex1 regex2) (concat str1 str2)) > then > (and (string-match regex1 str1) (string-match regex2 str2)) > > You need the empty regex case to work for the limiting case of this. (defun imply (a b) (or (not a) b)) (let ((regex1 "a") (regex2 "b") (str1 "ab") (str2 "x")) (imply (string-match (concat regex1 regex2) (concat str1 str2)) (and (string-match regex1 str1) (string-match regex2 str2)))) --> nil Perhaps you mean: (imply (and (string-match regex1 str1) (string-match regex2 str2)) (string-match (concat regex1 regex2) (concat str1 str2))) -- __Pascal Bourguignon__