This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


JavaRanch » Java Forums » Java » Java in General
Bookmark "Replacing substrings like ./ and ../" Watch "Replacing substrings like ./ and ../" New topic
Author

Replacing substrings like ./ and ../

Mahoney Futhark
Greenhorn

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

href="./i_am_going_to_mess_with_your_spider.htm"

or

href="../i_am_going_to_mess_with_your_spider_too.htm"

I have translated these into

href="http://www.i-feel-a-bit-creutzfeldt-jacob-ish.com/./i_am_going_to_mess_with_your_spider.htm"

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:

http://www.i-feel-a-bit-creutzfeldt-jacob-ish.coi_am_going_to_mess_with_your_spider.htm"

See my problem?


Any help appreciated.
Barry Higgins
Ranch Hand

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

becomes

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

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

Joined: Jan 10, 2002
Posts: 61315
    
  66

Moving to Java in General(intermediate)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: Replacing substrings like ./ and ../