From: pemente@northpark.edu (Eric Pement)
Subject: Re: regexp and strings you don't want
Date: 26 Aug 2003 15:19:49 -0700 [thread overview]
Message-ID: <227a55e9.0308261419.3e2da0d3@posting.google.com> (raw)
In-Reply-To: 6c185cf3.0308251145.6af55ffc@posting.google.com
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
next prev parent reply other threads:[~2003-08-26 22:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-25 19:45 regexp and strings you don't want Chaz
2003-08-25 20:17 ` Barry Margolin
2003-08-26 18:13 ` Chaz
2003-08-27 15:13 ` Kevin Rodgers
2003-08-29 15:50 ` Stefan Monnier
2003-08-26 22:19 ` Eric Pement [this message]
2003-08-27 20:26 ` Kai Großjohann
2003-08-29 16:14 ` Oliver Scholz
2003-08-29 18:50 ` Oliver Scholz
2003-08-29 19:58 ` Kai Großjohann
2003-08-29 20:38 ` Oliver Scholz
2003-08-30 14:50 ` Ilya Zakharevich
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=227a55e9.0308261419.3e2da0d3@posting.google.com \
--to=pemente@northpark.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).