Parse line of delimited text with JavaScript

Hi I'm quite new to javascript and I want to get extract a text but only a part of it. For example if it extracts this text:

honey_00.jpg :: 1200 x 1703 :: 369.39 KB

I want it to give me honey_00.jpg I don't want the other junk information. I only just want the file name. How can I do this?


Try this:

var filename = str.match(/.+\.jpg/);

Note that this will only work if the filename is at the beginning of the string and you're fetching a .jpg file.

To match a .jpg, .png, or .gif file, you can use this:

var filename = str.match(/.+\.(jpg|png|gif)/)[0];

Need Your Help

Grails domain class constraints for relation between fields

grails constraints grails-validation

I need to write Domain class constraint in Grails which says that one integer field must be greater or equal than the other.

Issue in Integrating In-app to the iOS application

ios apple in-app-purchase itunesconnect

Is it necessary to submit the app to implement In-App purchase..