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: Strange behavior in search-forward-regexp? Date: Fri, 10 Feb 2006 21:04:27 -0500 Organization: Symantec Message-ID: References: NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1139624091 22457 80.91.229.6 (11 Feb 2006 02:14:51 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 11 Feb 2006 02:14:51 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 11 03:14:40 2006 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1F7k8U-0000Lx-00 for ; Sat, 11 Feb 2006 03:05:18 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F7k8T-0002mm-0K for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Feb 2006 21:05:17 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail Original-NNTP-Posting-Date: Fri, 10 Feb 2006 20:04:27 -0600 Original-Newsgroups: gnu.emacs.help Mail-Copies-To: nobody User-Agent: MT-NewsWatcher/3.4 (PPC Mac OS X) X-Copies-To: never Original-Lines: 53 Original-NNTP-Posting-Host: 24.128.234.87 Original-X-Trace: sv3-rHH8rRCJkAOdTVRPlgo5Qu4qPP7e0aFoE5I+xDBoIT9PneCtNR3PHySZWXUeeh0ZRS+ehWc/HXiZf7B!BwhvSMX05nrbjIYhp7mygEhJhIM5caRlbb//TvXCs8RYDiACtCLj262RvBq1alO2tw1a627kuq6/!gyTG2zf5nCIaBFn21RJ3F0jk0haRKvLmgw== Original-X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Original-Xref: shelby.stanford.edu gnu.emacs.help:137506 Original-To: help-gnu-emacs@gnu.org 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:33132 Archived-At: In article , Mathias Dahl wrote: > Take these "buffers": > > Buffer 0: > > ---------- this line is not part of the buffer ---------- > row0;test0 > row1;test1 > row2;test2 > --------------------------------------------------------- > > Buffer 1: > > ---------- this line is not part of the buffer ---------- > > row0;test0 > row1;test1 > row2;test2 > --------------------------------------------------------- > > Evaluate these functions: > > (defun test1 () > (interactive) > (save-excursion > (goto-char (point-min)) > (if (search-forward-regexp "^[^;]+;.*test1" nil t) > (message (match-string-no-properties 0))))) > > (defun test2 () > (interactive) > (save-excursion > (goto-char (point-min)) > (if (search-forward-regexp "^.*test1" nil t) > (message (match-string-no-properties 0))))) > > In buffer 0, test1 and test2 willreturn the same result, "row1;test1", > but in buffer 1, test1 will return "\nrow1;test1" (\n is a newline) > and test2 "row1;test1". > > Can someone explain this to me? Why would, in the case of test1, the > newline be included just because the line before is empty? Because the regular expression . matches any character except newline, while [^;] matches any character except ';'. So newline matches [^;]. -- 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 ***