From: Robert Klemme Date: 2005-09-14T23:26:36+09:00 Subject: Re: Surprising Regexp Behavior James Edward Gray II wrote: > On Sep 14, 2005, at 8:51 AM, Robert Klemme wrote: > >> James Edward Gray II wrote: >> >>> 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. >>> >> >> This might be a bit more efficient (dunno how often you call it): >> >> def excerpt( textile, id ) >> html = sanitize(textilize(textile)) >> html.sub!(/

(.*?)<\/p>(.*)\Z/m) { $1.strip } >> html << link_to( '...', :action => :show, :id => id ) if >> $2 =~ >> /\S/ >> html >> end > > That's not equivalent. You're missing a space between html's content > and the ellipses. Right. But hey, that's an easy change, isn't it? :-) > But thanks for the ideas. You're welcome! robert