Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regular expression" Watch "Regular expression" New topic
Author

Regular expression

Adrian Enns
Ranch Hand

Joined: Aug 11, 2004
Posts: 48
I have a String variable that contains a bunch of $ symbols in it. I want to replace all of the "$" with blank text. I have tried String.replaceAll("$","") but it doesn't work.... does anybody know the regular expression that represents the $ sign?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Try "\\$"


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Adrian Enns
Ranch Hand

Joined: Aug 11, 2004
Posts: 48
Thanks, I figured it out... it's "[$]".
Srinivas Redd
Greenhorn

Joined: Mar 23, 2006
Posts: 17
Why "$" doesn't work ... ??? Why we have to give "[$]" ???


Srinvasa Reddy Thamma,<br />Chennai,India.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Originally posted by Srinivas Redd:
Why "$" doesn't work ... ??? Why we have to give "[$]" ???


The reason "$" does not work is because it has special meaning in a regular expression. It means the end of the line -- a marker for a carriage return and/or line feed.

BTW, "\\$" or "[$]" should both work.

Henry
[ April 06, 2006: Message edited by: Henry Wong ]
 
GeeCON Prague 2014
 
subject: Regular expression