[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regexp and strings you don't want
From: |
Eric Pement |
Subject: |
Re: regexp and strings you don't want |
Date: |
26 Aug 2003 15:19:49 -0700 |
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;/\<top\>/d' file
And in Emacs, mark the region and then do
M-| sed '/./{H;$!d;};x;/^\nThe/!d;/\<top\>/d' <RET>
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
- regexp and strings you don't want, Chaz, 2003/08/25
- Re: regexp and strings you don't want, Barry Margolin, 2003/08/25
- Re: regexp and strings you don't want,
Eric Pement <=
- Re: regexp and strings you don't want, Kai Großjohann, 2003/08/27
- Re: regexp and strings you don't want, Oliver Scholz, 2003/08/29
- Re: regexp and strings you don't want, Oliver Scholz, 2003/08/29
- Re: regexp and strings you don't want, Oliver Scholz, 2003/08/29
- Re: regexp and strings you don't want, Kai Großjohann, 2003/08/29
- Re: regexp and strings you don't want, Oliver Scholz, 2003/08/29
- Re: regexp and strings you don't want, Ilya Zakharevich, 2003/08/30