Using regular expressions, I would like to find and replace the word "foo" with the word "bar", but I want to do it in a way that preserves any capitalization that the word "foo" had before. So this text...
Foo the foo, and FOO too
would get changed to...
Bar the bar, and BAR too
Is there an easy way to do this with regular expressions?