On Mon, Aug 10, 2009 at 11:14 AM, Peter Ehrlich<crazedcougar / gmail.com> wro=
te:
> Hi
>
> This is probably a silly question, but I'm wondering what the best way
> is to scan a string for regular expression matches, and then link to it.
> It would be great to do it in one line, like this:
>
> =A0 =A0<% text.sub!(/#[-'A-Za-z]+/, link_to($&, tweet.category_name))%>
>
> But as the sub! has not completed, $& still refers to the old variable.
> I suppose I can just find the text I will be matching ahead of time,
> which would involve scanning the string twice, but there might be a
> better way. =A0Thoughts?

  text.sub!(/#[-'A-Za-z]+/) {|m| link_to(m, tweet.category_name))}


--=20
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale