javascript - JS - Regular Expression for 12hr Time Matching -
i attempting take regular expression being used in java application , use javascript.
(1[012]|[1-9]):[0-5][0-9](\\s)?(?i)(am|pm)
however, running issues. getting syntaxerror: invalid quantifier
error. escaped ?
, ended with
(1[012]|[1-9]):[0-5][0-9](\s)?(\?i)(am|pm)
however, when run following test, not matching properly:
"1:00 am".match(/(1[012]|[1-9]):[0-5][0-9](\s)?(\?i)(am|pm)/)
this regex should matching “1:00am”, “1:00 am”, ”1:00 am”
where going wrong?
try
"1:00 am".match(/(1[012]|[1-9]):[0-5][0-9]\s?(am|pm)/i)
the ignore case flag i
should @ end of regex
Comments
Post a Comment