I want to extract the complete path i.e the path followed by the host name of a URL in javascript.
var url = 'https://domain.us/file.php/fghfgh?id=1'
Here i want to extract /file.php/fghfgh?id=1
How can this achieve only using regular expression not by “document.createElement('a')” methode ?
I need the answer in regular expression ,
If you are accessing the location object, you could do
var path = location.href.replace(location.protocol+"//"+location.hostname,"")or
var path = location.pathname+location.searchIf you have # you may need to add it too as pointed out by just_mad:
var path = location.pathname+location.search+location.hash