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

1.2k 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 best solutions below

1
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
On

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

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