Kris Kris - 2 months ago 8
Javascript Question

JavaScript split a string at each occurrence of

JavaScript, How can we split...

Input String:

12:002:204:457:109:40


Output:

12:00
2:20
4:45
7:10
9:40

Answer

Using regex:

'12:002:204:457:109:40'.match(/(\d+:\d{2})/g).map(x => console.log(x))

(\d+:\d{2})

Regular expression visualization

Debuggex Demo

Further explanation: https://regex101.com/r/vV2wL5/1