1

Is there a simple regex to determine if a path is relative, or a hash?

I want to match these:

../index.php  
js/funct.js  
./home/
php/file.php?url=http://www.google.com
index.html#about=http://www.google.com

but not these:

http://www.google.com
http://google.com
/index.php
/
//google.com
#div4

here's what I have so far:

/^[^#\/]|\/\//.test(url)

But it's not working. Is there any way to get this to work?

btw I realize that //google.com is technically relative but I still don't want to match that case

I need this to be able to tell if I need to deal with a link after a pushState. Consider if I started on / and then pushStated to /page1/ then a link that has a href of 'index2.html' was supposed to go to /index2.html but will now go to /page1/index2.html

So I need to check for those types of relative paths.

qwertymk
  • 34,200
  • 28
  • 121
  • 184

0 Answers0