API give url but I want get only specific string in url. For example:
But I only want get: photo_xxx-xxx-xxx.png
How to split url at photo
and end at png
?
API give url but I want get only specific string in url. For example:
But I only want get: photo_xxx-xxx-xxx.png
How to split url at photo
and end at png
?
You can split by the string "%2F", get the last element in the array, split that by "? " and get the first element in that
const splitBySlash = url.split('%2F')
const filePath = splitBySlash[splitBySlash.length - 1]
const splitByQuestion = filePath.split('?')
const file = splitByQuestion[0]
learn about regex.
The regex to use is: /photo_(.*).png/
;
see below how to use it
var res = "https://firebasestorage.googleapis.com/v0/b/project-xxxx.appspot.com/o/folder_lib%2Fphoto_xxx-xxx-xxx.png?alt=media&token=xxx-xxx-xxx20-5-2016.csv?alt=media&token=b5d45a7f-3ab7-4f9b-b661-3a2187adxxxx".match(/photo_(.*).png/)[0];
console.log(res)
Here's a nice app to practice and test yourself