This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes Replacing substrings like ./ and ../ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Replacing substrings like ./ and ../" Watch "Replacing substrings like ./ and ../" New topic

Replacing substrings like ./ and ../

Mahoney Futhark

Joined: Nov 15, 2004
Posts: 5
I'm building a simple spider, but I am stuck right now as I can't format URL's the right way. Some websites uses relative addressing in their links like




I have translated these into


So I need to remove substrings like ./ and ../, probably also //.

The problem is I can't. I've tried using string.replaceAll("./", ""),
but that removes other things too as the . is treated as meaning "one char of any kind".

so the previous URL translated would become:


See my problem?

Any help appreciated.
Barry Higgins
Ranch Hand

Joined: Jun 05, 2003
Posts: 89
Have you tried delimiting the "." using "\\."


I haven't tried it here myself but it should work!
Mahoney Futhark

Joined: Nov 15, 2004
Posts: 5
Thanks, worked just fine
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Moving to Java in General(intermediate)

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Replacing substrings like ./ and ../
It's not a secret anymore!