From: "Peña, Botp" Date: 2008-08-13T11:40:37+09:00 Subject: Re: regular expresson isue From: Raj Singh [mailto:neeraj.jsr@gmail.com] # ([0-9]|0[0-9]|1[012]):([0-9]|0[0-9]|[1-5][0-9])\s*(am|pm) # I don't want this regext to match 13:45 PM because the the numerical # value before the colon should be limited to 12. How to fix it? Hi Raj, the 13 is matching ([0-9]|0[0-9]|1[012]) ^^^^^ this because the regex will match the 3. the regex did not care if it had a 1 before it. You may want to tell it to not match any preceding digit (or else it be a beginning of the string) if you want a stand alone digit. eg, you may want to achor/prefix it w the ^ (for beginning of string) or \D (to represent a non-digit character) sample tests, irb(main):112:0> re = /((^|\D)[0-9]|0[0-9]|1[012]):/ => /((^|\D)[0-9]|0[0-9]|1[012]):/ irb(main):113:0> re =~ "1:" => 0 irb(main):114:0> re =~ " 1:" => 0 irb(main):117:0> re =~ "13:" => nil irb(main):122:0> re =~ "01:" => 0 irb(main):123:0> re =~ "11:" => 0 irb(main):124:0> re =~ "12:" => 0 kind regards -botp