File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 63854

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!