Find and replace in a block of text.

Posted by David Tildon on Stack Overflow See other posts from Stack Overflow or by David Tildon
Published on 2010-03-20T07:38:54Z Indexed on 2010/03/20 7:41 UTC
Read the original article Hit count: 546

Filed under:
|

I have a database full of text fields that look like this:

(paragraph of normal text)

image:blog/clownboy.jpg

(another paragraph)

I'm trying to write a view helper for Rails that will take one of these big blocks of text, find bits like "image:blog/clownboy.jpg" and replace them with the corresponding <img src="blog/clownboy.jpg"> (without disturbing the surrounding whitespace) before outputting it to the user. I've been trying for an hour or so now, but I'm new to Ruby and the regular expressions are still a bit beyond me.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails