Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replacing substrings like ./ and ../

 
Mahoney Futhark
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried delimiting the "." using "\\."
so

becomes

I haven't tried it here myself but it should work!
 
Mahoney Futhark
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, worked just fine
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java in General(intermediate)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic