I need to extract the directory and file name in a different input of user URL's.
Some examples would include:
What I really need is the TOP_PROD_IMAGE
and WS-25612-BK_IMRO_1.jpg
file name.
So I would need to account for users who enter http://
or https://
or just www
. so I tried using string.split('/')
but that obviously wouldn't work in all cases. Is there something that could give me an array despite the double //
in cases where user enters http? Thanks!
Consider:
const [file, folder] = url.split('/').reverse();
With this you wouldn't need to consider http://
or any //
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With