From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: pemente@northpark.edu (Eric Pement) Newsgroups: gmane.emacs.help Subject: Re: regexp and strings you don't want Date: 26 Aug 2003 15:19:49 -0700 Organization: http://groups.google.com/ Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <227a55e9.0308261419.3e2da0d3@posting.google.com> References: <6c185cf3.0308251145.6af55ffc@posting.google.com> NNTP-Posting-Host: deer.gmane.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1061938316 13156 80.91.224.253 (26 Aug 2003 22:51:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 26 Aug 2003 22:51:56 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 27 00:51:55 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19rmfK-0003QB-00 for ; Wed, 27 Aug 2003 00:51:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 19rmZT-0001Br-T5 for geh-help-gnu-emacs@m.gmane.org; Tue, 26 Aug 2003 18:45:51 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews1.google.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 35 Original-NNTP-Posting-Host: 66.185.249.144 Original-X-Trace: posting.google.com 1061936391 17013 127.0.0.1 (26 Aug 2003 22:19:51 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: 26 Aug 2003 22:19:51 GMT Original-Xref: shelby.stanford.edu gnu.emacs.help:116162 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:12081 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:12081 chaz2@thedoghousemail.com (Chaz) wrote in message news:<6c185cf3.0308251145.6af55ffc@posting.google.com>... > I know that ^ at the start of [ ] excludes individual characters (or > ranges of characters) from a regular expression search, but is there > an equivalent to eliminate strings? That is, how can I search for a > regular expression that does not include a specified string? > > For example, how can I search for a paragraph beginning with "The" > that does NOT include the word "top"? A big problem is that paragraphs are multi-line objects and they aren't amenable to simple grep operations or "M-x occur", which I'm using much more frequently now. But to answer your question more directly, here's how to locate the matching paragraphs (separated by blank lines) in sed: sed '/./{H;$!d;};x;/^\nThe/!d;/\/d' file And in Emacs, mark the region and then do M-| sed '/./{H;$!d;};x;/^\nThe/!d;/\/d' M-| runs shell-command-on-region, sending the results to a new window. This will show you how many paragraphs match your specification. It's not like "M-x occur", which will take you directly to the matching lines there. However, this script will let you see how many paragraphs match your specification, without leaving Emacs. I presume you have GNU sed; if not, omit the \< and \> characters, which are GNU options to match whole words. If you use WinNT Emacs, wrap the sed script in "double quotes" instead of 'single quotes'. Hope this helps. -- Eric Pement