28 users online (1 members and 27 guests)  


  Results 1 to 3 of 3

Related

  1. how to match the characters in file ?    Forum: CGI Perl Forum
    Replies: 1
  2. Array to string    Forum: PHP Forum
    Replies: 3
  3. SELECT MATCH ... AGAINST problem    Forum: PHP Forum
    Replies: 0
  4. unusual string    Forum: Javascript Forum
    Replies: 2
  5. Replies: 2
  1. #1
    eruisi's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    1

    Question How to match a time string

    the format is hh:mm:a/pm
    need to be able to find out illegal time like 3:0pm, 99:00pm
    I tried several candidates:
    m/[01]?[0-9]:[0-5][0-9](am|pm)/i
    - I know this is not correct, but at least it should filter out 99:00pm.

    m/((1[0-2])|[0-9]):[0-5][0-9](am|pm)/i

    none of them can filtering 99:00pm but I can't think it through.
    Can anyone point out why these patterns are wrong.

  2. #2
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: How to match a time string

    hiya,
    Im interested in what context you are using this. You can use formatted output to take input from a user, i.e. if they enter 4:01 and pressed submit (or whatever) it can format it automatically into 04:01 using something like %02d...
    Maybe this will help...
    my ($sec, $min, $hour)=gmtime;
    $time = sprintf ('_%02d%02d%02d', $hour, $min, $sec);
    the result is i.e. 22:10:47
    If you aren't using this context please expain and i will help you with your regular expressions

  3. #3
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: How to match a time string

    Look into using Date::Manip
    or if you can view Perl Cookbook (p.100 (3.7)) it tells you how there. But I can't be bothered to write it all out hehe



Tags for this Thread