I need extract only "40:37.298s" from:
Total time: 40:37.298s
using JS, but I`m new in JS, can some one help?
There are many ways to do this. Here's one:
var str = "Total time: 40:37.298s";
str.split(": ")[1]
In most cases I prefer splitting on some known pivot, rather than trying to extract a specific substring (as others have shown) for the following reasons:
var time = 'Total time: 40:37.298s';
time = time.match(/\d{1,2}:\d{1,2}\.\d+s/);
var item = 'Total time: 40:37.298s';
var pattern = /\d{1,2}\:\d{2}\.\d{3}s/g;
var res = pattern.exec(item);
That is:
.exec() will assign matches in an Array to the res, so to get the actual matched value from the code above, you'll need to query res[0].