M
M
Maxim2015-10-08 11:29:31
JavaScript
Maxim, 2015-10-08 11:29:31

How to parse URL from JS?

I've always had a hard time with regulars.
Help me compose a regular expression to
http://example.com/admin/page/1
get the same number 1 from the url of the form. The number may not be "1" at all, but let's say 2 or 536

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivanq, 2015-10-08
@maxpointn2point

var path = location.pathname.split('/');
var path = path[path.length-1];

PROFIT!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question