-3

I'm using filestack, when ever I upload an image it creates an unique url for the uploaded Image. I want to get hold of a specific part of a url to a variable.

https://www.filestackapi.com/api/file/qiXTZ0dQUGPQRG4GH0Cy

https://www.filestackapi.com/api/file/"qiXTZ0dQUGPQRG4GH0Cy"

The above Url belongs to an image, but I want get hold of the quoted part to a variable, how to do that?

5
  • Split by / get last Commented Apr 21, 2016 at 15:36
  • Use regex ([^\]+$) and get first captured group Commented Apr 21, 2016 at 15:36
  • Substring with lastIndexOf. Commented Apr 21, 2016 at 15:36
  • Possible duplicate of Get filename from URL using JavaScript Commented Apr 21, 2016 at 17:46
  • Did you even try looking for an answer? (746 results) Commented Apr 21, 2016 at 17:47

1 Answer 1

3

You can search for the last index of / in the url then make a substring of the url starting from that point.

var url = 'https://www.filestackapi.com/api/file/qiXTZ0dQUGPQRG4GH0Cy';
var lastIndex = url.lastIndexOf("/");
var searched = url.substring(lastIndex + 1);

// searched = qiXTZ0dQUGPQRG4GH0Cy
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, thanks a lot.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.