How to find current page url (like "index.html")?

1.1k views Asked by At

With string http://www.example.com/section_one/index.html how can I return index using RegExp?
P.S.: Returning index.html is accepted too.

2

There are 2 answers

1
R4nc1d On BEST ANSWER

You can try the following. Fiddle

var url = "http://www.example.com/section_one/index.html";
var filename = url.match(/[^\\/]+$/)[0];
7
Hammad On

You don't need to use regex for that. Its simple:

var url = document.URL;
var currentPage= url.split("/").pop();