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 ?
2 Answers
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("/")
- Split on
/ - Slice out the first 5 items in the array.
- Re-join them together with a
/
Results: "http://www.example.cz/example/example-example"
1 Comment
Timeout
@user3276426 Yes, that property includes protocol as well.