Y
Y
Yura_Mart2019-03-06 12:56:49
JavaScript
Yura_Mart, 2019-03-06 12:56:49

How to take the value after the last "/" from the URL if the entire length of the url is unknown?

There are URLs of different lengths:
http://000.000.000.00:3000/index.html
file:///android_asset/www/index.html
file:///data/user/0/files/android_asset/www/index.html
How can I take the value of index.html from these examples? (or together with a slash: /index.html)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hzzzzl, 2019-03-06
@Yura_Mart

bla = 'file:///data/user/0/files/android_asset/www/index.html'.split('/')
bla[bla.length - 1]

A
Alexey, 2019-03-06
@skazi_premiere

Or regular season

bla = 'file:///data/user/0/files/android_asset/www/index.html'.match(/(?<=\/)\w*\.\w*$/gmi) //Без слеша
bla = 'file:///data/user/0/files/android_asset/www/index.html'.match(/\/\w*\.\w*$/gmi) //Со слешем

D
Durd0m, 2019-06-04
@Durd0m

console.log(window.location.pathname);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question