M
mw
Hello,
I am trying to make a regex for a 12 hour clock, and I can't seem to
get it just right.
What I have now is
var regexmatch = /(1[012]:[0-5][0-9]|[1-9]:[0-5][0-9])\s((a\.m\.)|(p
\.m\.))/i
My thinking is that the first part will filter out the time and the |
will correctly check the two possibilities
1:00 --> 9:59
and then the other part
10:00-->12:59
then a space which is \s
then the tricky part where I'm pretty sure the bug is: the a.m. or
p.m. I think it is my inexperience with the () that is messing this
up. I've tried all sorts of variations for the last part, but I am
stuck. I keep ending up with expressions that are too liberal and
will allow times like 23:23 p.m. through. Please excuse my slow-
learning of the subject as tonight is the first time I've touched
regex in js and really regex at all. Also, I'm sorry for the a.m.
p.m. part. It has gone from OK looking to ugly parenthesis nightmare
in my attempts to make it work correctly. (I've tried other without
() versions, etc, but can't seem to hit it correctly)
Thanks in advance,
mw
I am trying to make a regex for a 12 hour clock, and I can't seem to
get it just right.
What I have now is
var regexmatch = /(1[012]:[0-5][0-9]|[1-9]:[0-5][0-9])\s((a\.m\.)|(p
\.m\.))/i
My thinking is that the first part will filter out the time and the |
will correctly check the two possibilities
1:00 --> 9:59
and then the other part
10:00-->12:59
then a space which is \s
then the tricky part where I'm pretty sure the bug is: the a.m. or
p.m. I think it is my inexperience with the () that is messing this
up. I've tried all sorts of variations for the last part, but I am
stuck. I keep ending up with expressions that are too liberal and
will allow times like 23:23 p.m. through. Please excuse my slow-
learning of the subject as tonight is the first time I've touched
regex in js and really regex at all. Also, I'm sorry for the a.m.
p.m. part. It has gone from OK looking to ugly parenthesis nightmare
in my attempts to make it work correctly. (I've tried other without
() versions, etc, but can't seem to hit it correctly)
Thanks in advance,
mw