From: James Edward Gray II Date: 2005-09-14T22:32:47+09:00 Subject: Re: Surprising Regexp Behavior On Sep 14, 2005, at 8:21 AM, Robert Klemme wrote: > Ah! In that case I'd something like: > > html.sub!(/(

)(.*?)(<\/p>)(.*)/) { $1 << $2.strip << $3 } > html.sub!(/

(.*?)<\/p>(.*)/) { "

#{$1.strip}

" } The method takes a chunk of HTML and pulls the first paragraph out of it (minus the

and

tags). But I want to know if there was other content, so I can add an ellipses if needed. Here's the entire method, defined in a Rails helper module: def excerpt( textile, id ) html = sanitize(textilize(textile)) html.sub!(/

(.*?)<\/p>(.*)\Z/m) { $1.strip } if $2 =~ /\S/ "#{html} #{link_to '...', :action => :show, :id => id}" else html end end It works as expected now. James Edward Gray II