matthias:
> 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 looks like you'd be happy with
,y/^\..*\n/ |fmt
or, avoiding fmt of zero-length ranges (just a little faster)
,y/(^\..*\n)+/ |fmt
rog:
> 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?
it's trivial but it doesn't make sense.
in plan 9 regular expressions (as in awk), the semantics
are that the leftmost longest overall match is chosen,
even if that means not repeating a * as much as possible.
for example, consider /a*(ab)?/ against "aab".
perl will match "aa" because the a* greedily grabs "aa"
leaving (ab)? no choice but to match the empty string.
plan 9 will match "aab" because that is a longer match:
the a* selflessly matches less so that the overall
expression can match more.
since plan 9 doesn't have the greedy-like-perl * operator,
it doesn't make sense to think about adding a
non-greedy-like-perl * operator.
the y iterator handles about 90% of the reasons people use
non-greedy operators, so i'm happy to leave things as is.
russ