Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript mins and seconds into seconds

I have a string being grabbed from a page in the format "4m 26s", how can I strip this into just seconds?

Many thanks,

like image 951
Pez Cuckow Avatar asked May 11 '26 01:05

Pez Cuckow


1 Answers

Simple regex will work:

var s = '21m 06s';

var m = /(\d{1,2})m\s(\d{1,2})s/.exec(s);

var mins = parseInt(m[1], 10);
var secs = parseInt(m[2], 10);
like image 192
Evan Trimboli Avatar answered May 13 '26 15:05

Evan Trimboli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!