Problem with ^ while using java.lang.String.replaceAll method

Hi folks!!

I have a string which contains the character ^. Now, I tried removing this by using replaceAll method in String... but I got weird output!! Just check it out......

This is my program-

class Test

{

public static void main(String[] args)

{

String string = "^";

System.out.println(string);

string = string.replaceAll("^","here's one!!");

System.out.println(string);

}

}

I saved it in C:\workarea and compiled it. But when I run it i got-

C:\workarea>java Test

^

here's one!!^

^ isn't removed but the replace string comes in the first position!!!!

Can anybody tell what's going on? Is it a mistake in the program or ma mistake with my eyes? :-0

[774 byte] By [jozzyjacza] at [2007-10-3 3:26:54]
# 1
string = string.replaceAll("\\^","here's one!!");
PhHeina at 2007-7-14 21:20:08 > top of Java-index,Java Essentials,Java Programming...
# 2
replaceAll takes a regex.^ is a special char for regexes.You need to escape it."\\^" I think
mlka at 2007-7-14 21:20:08 > top of Java-index,Java Essentials,Java Programming...
# 3
gee... i din know that...thanks alot!! :-)
jozzyjacza at 2007-7-14 21:20:08 > top of Java-index,Java Essentials,Java Programming...