• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Replacing substrings like ./ and ../

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, worked just fine
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Java in General(intermediate)
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic