Reputation: 23
Good evening, I have a problem to find string from url address when I click on next page, for example I have url: http://www.example.cz/example/example-example/page/2/ <- hyphen is optinal. I need to find part http://www.example.cz/example/example-example/ <- without part page/number/ and save it to variable. Can you guys help me how to do it ?
Upvotes: 0
Views: 40
Reputation: 126
If page is always in the url and also what needs to be removed, you can simply split on 'page' and take the first element of the resulting array.
var url = "http://www.example.cz/example/example-example/page/2/",
urlParsed = url.split("page")[0];
Upvotes: 0
Reputation: 7909
You could split on /
and then reform the string.
For example (this assumes http://
is part of the string):
"http://www.example.cz/example/example-example/page/2/".split("/").slice(0,5).join("/")
/
/
Results: "http://www.example.cz/example/example-example"
Upvotes: 1