This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

A small problem in replaceAll  RSS feed

 
Neha Mohit
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers,



Why does $people$ not getting replaced by Ranchers .



Thanks in advance
neha
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you check the API for String's replaceAll method, you will see that it "Replaces each substring of this string that matches the given regular expression..."

In a regular expression, the $ char has special meaning (it matches the end of a line). So to match the literal $ character in a String, you need to use an escape sequence. See the "Backslashes, escapes, and quoting" topic under the regular expression link above.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!