9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] regexp to match paragraphs in troff documents
Date: Thu,  7 Jun 2007 15:50:30 +0100	[thread overview]
Message-ID: <f73b1f8195b654c13724f293b5020909@vitanuova.com> (raw)
In-Reply-To: <082ffdbcfda12b51637105e95ea479c8@mteege.de>

> I've tried to pipe paragraphs of a troff document to fmt but I
> have problems with the correct regular expression. My first attempt
> "/^\.[A-Z]++.*\n(^[^]*)*\n^\.[A-Z]++.*\n/" matches only any second
> paragraph because the expression is overlapping. Does anyone have a nice
> idea to match troff parapgraphs?

it's not easy (maybe not possible?) to do what you're doing unless you
can unambiguously find the start and end of paragraphs (e.g. between ^\.PP and ^$),
in which case you can use something like:

,x/^\.PP/.,/^$/|fmt

for other cases, i suppose it might be nice to have non-greedy matching,
in which case you could do something like:
,x/^\.[A-Z][A-Z].*\n(.*\n)*?\.[A-Z][A-Z]\n/
russ: how easy do you think it would be to put non-greedy matching into
the acme/sam regexp engine?

PS. ++ means exactly the same as +


  reply	other threads:[~2007-06-07 14:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-07 14:28 Matthias Teege
2007-06-07 14:50 ` rog [this message]
2007-06-07 17:46 ` Russ Cox

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=f73b1f8195b654c13724f293b5020909@vitanuova.com \
    --to=rog@vitanuova.com \
    --cc=9fans@cse.psu.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 NNTP newsgroup(s).