Home arrow static arrow Java Programming [Archive] - Escaping $ sign
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Escaping $ sign
This topic has 3 replies on 1 page.

Posts:3
Registered: 8/3/04
Escaping $ sign  
Aug 3, 2004 4:49 PM



 
How to escape dollar sign using RegEx?

I m using gnu.regEx.RX.
///////////////////////////////////
String message = "Print the value as <#1#>";
String replaceWith = "$10,030.99";
String pattern = "<#" + (i + 1) + "#>";
if (message.indexOf(pattern) >= 0) {
RE regexp = new RE(pattern);
message = regexp.substitute(message, replaceWith);
System.out.println(message);
}
//////////////////////////
The output is
Print the value as 0,030.99

I want the output as,
Print the value as $10,030.99.

Any ideas? Greatly appreciate your help on this. Thanks in advance.

Elangs.
 

Posts:10,967
Registered: 4/7/01
Re: Escaping $ sign  
Aug 3, 2004 5:17 PM (reply 1 of 3)



 
Probably not all of your question/problem, but Java escapes it this way:

"print the value as xx".replaceAll("xx", "
$10,030.99"));

I don't believe that gnu and Java use the same syntax.
 

Posts:3
Registered: 8/3/04
Re: Escaping $ sign  
Aug 3, 2004 5:31 PM (reply 2 of 3)



 
Probably not all of your question/problem, but Java
escapes it this way:

"print the value as xx".replaceAll("xx",
"
$10,030.99"));

I don't believe that gnu and Java use the same syntax.

I had tried these before posting my question. This prints as follows.

"Print the value as $\0,030.99.00"

Not sure why, though.

Elangovan.s
 

Posts:2,391
Registered: 9/26/00
Re: Escaping $ sign  
Aug 3, 2004 7:13 PM (reply 3 of 3)



 
"Print the value as $\0,030.99.00"

I don't know why it's doing that (looks like a bug to me), but you can disable variable interpolation altogether by using the appropriate flag:
  RE regexp = new RE(pattern, RE.REG_NO_INTERPOLATE);
 
This topic has 3 replies on 1 page.