Чтобы убедиться, что значение представляет время, я бы использовал что-то вроде этого:
/^[0-5]?\d(?::[0-5]?\d){1,2}/gm
Regex demo .
Разбивка:
^ # The beginning of the string/line.
[0-5]? # And optional number between 0 and 5.
\d # Any digit.
(?: # The start of a non-capturing group.
: # Matches the character ":" literally.
[0-5]?\d # Any digit, optionally preceded by a number between 0 and 5.
) # The end of the non-capturing group.
{1,2} # Match between one and two times of the previous group (`ss` or `mm:ss`).
Пример JavaScript:
function timestampify(text) {
return text.replace(/^[0-5]?\d(?::[0-5]?\d){1,2}/gm, '<a data-time="$&" class="timestamp-link">$&</a>')
}
var text = `
0:00 - Rhythm Heaven - Rhythm Calligraphy
1:46 - Mario Party 6 - Night at the Garage
3:00 - POKEMON: Super Mystery Dungeon - Onward, Expedition Society!
36:10 - Mario Party 9 - DK's Jungle Ruins
47:23 - Rhythm Heaven - Rhythm Calligraphy
01:03:23 - Rhythm Heaven Fever: Prologues - Power Calligraphy Prologue
`
console.log(timestampify(text))