From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: string-match bug? Date: Tue, 08 Dec 2009 15:48:01 -0500 Organization: A noiseless patient Spider Message-ID: 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 X-Trace: ger.gmane.org 1260308522 9186 80.91.229.12 (8 Dec 2009 21:42:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 8 Dec 2009 21:42:02 +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:41:56 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 1NI7oi-000506-4t for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Dec 2009 22:41:56 +0100 Original-Received: from localhost ([127.0.0.1]:35960 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NI7oh-0008UE-Sk for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Dec 2009 16:41:55 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!barmar.motzarella.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 52 Original-X-Trace: news.eternal-september.org U2FsdGVkX1+YrdsUz2BifIMQ+2rErcWjy/f+EGM+GEwzgm+ZnNmZQp+E0IazAou0lyO78gEfKT+I1HRh1C8L0BRpyIjrPojvW7otT2NFMIc7IXgP7m7rnqAgBNAbfnmXaictd8X54sY= Original-X-Complaints-To: abuse@eternal-september.org Original-NNTP-Posting-Date: Tue, 8 Dec 2009 20:48:01 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Auth-Sender: U2FsdGVkX1/ZAEGL2GBvtosn7sPXlGdpMgshSJzCQLg= Cancel-Lock: sha1:++YRpqt4YmtGOsOHmlcwHqPpKB0= Original-Xref: news.stanford.edu gnu.emacs.help:175432 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:70507 Archived-At: 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. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***