I have a line captured from a page in “4m 26s” format, how can I split this into a few seconds?
Many thanks,
var str = "4m 26s"; var arr = str.split(" "); var sec = parseInt(arr[0], 10)*60 + parseInt(arr[1], 10);
You do not need regex if you use parseInt ...
A 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);
Non-modal path:
Do string.split(" ")in your line; then do string.slice(0, -1)on both arrays. Multiply the first entry by 60. Add them together.
string.split(" ")
string.slice(0, -1)
var str = "4m 26s"; console.log(str.match(/\d+m\s+(\d+)s/)[1]);//26
Source: https://habr.com/ru/post/1752058/More articles:Использование fadeIn() и fadeOut() с помощью jQuery и Prototype одновременно - jqueryEclipse XML Editor in Flash Builder - eclipseDuplicate literals and hard coding - c ++GTK window motion animation? - linuxLinux implementation on Solaris - linuxC ++ template tree question template - c ++How to determine if a relative path is outside the given path - c #Understanding template classes in C ++ - problem with new operator - c ++Why does a new window open when I click the Submit button in the pop-up menu? - asp.netGWT FocusPanel, tab and focus handlers - cross-browserAll Articles