all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Barry Margolin <barmar@alum.mit.edu>
Subject: Re: Strange behavior in search-forward-regexp?
Date: Fri, 10 Feb 2006 21:04:27 -0500	[thread overview]
Message-ID: <barmar-78BBFE.21042710022006@comcast.dca.giganews.com> (raw)
In-Reply-To: m2wtg21xhd.fsf@gmail.com

In article <m2wtg21xhd.fsf@gmail.com>,
 Mathias Dahl <brakjoller@gmail.com> 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 ***

  reply	other threads:[~2006-02-11  2:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-11  1:43 Strange behavior in search-forward-regexp? Mathias Dahl
2006-02-11  2:04 ` Barry Margolin [this message]
2006-02-11  9:45   ` Mathias Dahl
2006-02-12  9:58     ` Barry Margolin
2006-02-12 14:58       ` Mathias Dahl
2006-02-12 21:19         ` Barry Margolin
2006-02-11 11:48 ` Peter Dyballa
2006-02-11 19:00   ` Mattis
2006-02-11 19:33     ` Peter Dyballa
     [not found]     ` <mailman.17.1139690074.2858.help-gnu-emacs@gnu.org>
2006-02-11 21:43       ` Mathias Dahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=barmar-78BBFE.21042710022006@comcast.dca.giganews.com \
    --to=barmar@alum.mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.