Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular expression

 
Adrian Enns
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21409
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try "\\$"
 
Adrian Enns
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I figured it out... it's "[$]".
 
Srinivas Redd
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why "$" doesn't work ... ??? Why we have to give "[$]" ???
 
Henry Wong
author
Marshal
Pie
Posts: 21409
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic