I have a regex to parse ISO8601 times, and it tests beautifully in RegexBuddy, but when I run it in JavaScript, either using jsbin.com or my Node.js program, the last value passes when it should fail (12:30.05 PM).
It seems to think the second :
is ok with a .
I have tried specifying \:
, [:]
and other variations, but in JavaScript it always returns true.
Anybody seen this behavior before?
var vals = [
'04:05:06.789',
'05:05:06',
'04:05',
'040506',
'04:05 AM',
'04:05 PM',
'04:05:06.789-8',
'04:05:06-08:00',
'04:05-08:00',
'04:05-08',
'04:05:06 PST',
'04:05:06 America/New_York',
'12:30.05 PM'
];
vals.forEach(val => {
console.log(/^[01][0-9]:?[0-5][0-9](:?([0-5][0-9])((\.)?(\d{0,14})?)?)?(\s[AaPp][Mm])?(([+-]\d{1,2}(:[0-2][0-9])?)|(\s(\w)+)|((\w)+\/(\w)+)|())?/.test(val))
});