On Sep 14, 2005, at 8:21 AM, Robert Klemme wrote:

> Ah!  In that case I'd something like:
>
> html.sub!(/(<p>)(.*?)(<\/p>)(.*)/) { $1 << $2.strip << $3 }
> html.sub!(/<p>(.*?)<\/p>(.*)/) { "<p>#{$1.strip}</p>" }

The method takes a chunk of HTML and pulls the first paragraph out of  
it (minus the <p> and </p> 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>(.*?)<\/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