Find and replace in a block of text.
- by David Tildon
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.