Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex URL Path from URL

I am having a little bit of regex trouble.

I am trying to get the path in this url videoplay.

http://video.google.co.uk:80/videoplay?docid=-7246927612831078230&hl=en#hello

If I use this regex /.+ it matches /video as well.

I would need some kind of anti / negative match to not include //

like image 946
ThomasReggi Avatar asked Aug 19 '12 01:08

ThomasReggi


1 Answers

In case if you need this for your JavaScript web-app: the best answer I ever found on this topic is here. Basic (and also original) version of the code looks like this:

var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";

parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port;     // => "3000"
parser.pathname; // => "/pathname/"
parser.search;   // => "?search=test"
parser.hash;     // => "#hash"
parser.host;     // => "example.com:3000"

Thank you John Long, you made by day!

like image 140
Vlad Mysla Avatar answered Sep 20 '22 04:09

Vlad Mysla