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..

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.