I am having date string in following form x.toLocaleString().toLowerCase()
"fri apr 21 2017 19:18:21 gmt+0530 (india standard time)" want to extract only 19:18:21 .How do extract these value only from whole string using javascript regular expression.
2 Answers
The REGEX should filter out invalid time formats like "60:23:22" which does not belong to either 12H or 24H formats, So it should be
var regExp = /([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/g;
var str = "19:18:21 65:45:33 12:23:23 30:34:22 100:22:22 10:22:222";
var regExp = /\b([01]\d|2[0-3]):[0-5]\d:[0-5]\d\b/g;
console.log(str.match(regExp));