Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Regular expression  RSS feed

 
Adrian Enns
Ranch Hand
Posts: 51
  • 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
Sheriff
Posts: 22846
119
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: 51
  • 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
Sheriff
Posts: 22846
119
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!