replaceAll with metacharacter

[nobr]Hi all

I need to replace a String contains $ sign with another String contains $sign. Since $ sign have special meaning and need to add metacharacter between the message. I have some problem when the String used for replacement have $ sign. A exception generated

java.lang.IllegalArgumentException: Illegal group reference

Here are my coding

import java.util.regex.Pattern;

import java.util.regex.Matcher;

publicfinalclass ReplaceTest{

privatestatic String REGEX ="\\Q$person.firstName $person.lastName<br/>\\E";

privatestatic String INPUT ="

#foreach($person in $personList)<br />$person.firstName $person.lastName<br/>#end

";

privatestatic String REPLACE ="\\$person.firstName1 \\$person.lastName1<br/>";

privatestatic String REPLACE1 ="\\Q$person.firstName1 $person.lastName1<br/>\\E";

publicstaticvoid main(String[] argv){

Pattern p = Pattern.compile(REGEX);

Matcher m = p.matcher(INPUT);

INPUT = m.replaceAll(REPLACE);

System.out.println(INPUT);

}

}

using REPLACE without problem but not REPLACE1. Since this String will read from file rather than input at coding level, I cannot add backslash in front of every $. Any solution for this? Thanks.

regards

wayne[/nobr]

[2071 byte] By [waya] at [2007-11-27 11:52:40]
# 1

You programmer should write a filtering code for such case.

hiwaa at 2007-7-29 18:45:57 > top of Java-index,Java Essentials,New To Java...
# 2

Surfing 1.5 days and found the solution finally.

http://forum.java.sun.com/thread.jspa?threadID=561335&messageID=2760175

waya at 2007-7-29 18:45:57 > top of Java-index,Java Essentials,New To Java...