String.replaceAll problem

I need to replace a single quote ( ' ) in a string with two single quotes. I am trying to use String.replaceAll method but it does not work. I guess my regular expression is not correct. I have tried several combinations already.

text.replaceAll(".'.","''");

text.replaceAll("'","''");

text.replaceAll("\\'","''");

None of them have worked. It does not change the text as I'd like it to.

[579 byte] By [lgarcia3a] at [2007-11-27 10:44:52]
# 1

They work perfectly.

Strings are immutable.

str = str.replaceAll("'", "''");

OR

str2 = str1.replaceAl(...);

depending on whether you need to keep a reference to the original string.

jverda at 2007-7-28 20:09:35 > top of Java-index,Java Essentials,Java Programming...
# 2

UGGGRRRR!!!!

~!@#$%^&*!!!

Yep, you are right... not enough coffee today I guess :))

lgarcia3a at 2007-7-28 20:09:35 > top of Java-index,Java Essentials,Java Programming...
# 3

It's been at least a week since I've posted this:

Since regex patterns are involved, you can use the simpler replace method:

str = str.replace("'", "''");

By the way, I hope you not doing this to insert text into a database!

BigDaddyLoveHandlesa at 2007-7-28 20:09:35 > top of Java-index,Java Essentials,Java Programming...