Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Weird Regexes Stuff

by Samy_rio (Vicar)
on Aug 18, 2011 at 18:00 UTC ( #921034=note: print w/replies, xml ) Need Help??


in reply to Weird Regexes Stuff

Updated

this may help you

#!/usr/bin/perl -w use strict; use warnings; my $input = 'All the following should be acceptable: 12:00am, 5:00pm, +8:30AM. These should probably not be accepted: 3:00,2:60am, 99:00am, +3:0pm, 29:00AM.'; while ($input =~ m/\W([1-9]|[01][0-2]|2[0-3]):[0-5][0-9][ap]m/gsi) { print "This is a valid time!\t$&\n"; } __END__ OUTPUT This is a valid time! 12:00am This is a valid time! 5:00pm This is a valid time! 8:30AM

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Replies are listed 'Best First'.
Re^2: Weird Regexes Stuff
by AnomalousMonk (Chancellor) on Aug 18, 2011 at 18:11 UTC
    >perl -wMstrict -le "my $input = '12:00AM 29:00AM'; while ($input =~ m/\W(0|[0-2]?[0-9]):[0-5][0-9][ap]m/gsi) { print qq{This is a valid time!\t'$&'}; } " This is a valid time! ' 29:00AM'
Re^2: Weird Regexes Stuff
by AnomalousMonk (Chancellor) on Aug 19, 2011 at 07:47 UTC

    The updated solution still has a problem, IMO, with that pesky  \W anchoring the start of the match. Is the following really what you intend?

    >perl -wMstrict -le "my $input = '12:00am, 5:00pm,8:30AM'; while ($input =~ m/\W([1-9]|[01][0-2]|2[0-3]):[0-5][0-9][ap]m/gsi) { print qq{This is a valid time!\t$&}; } " This is a valid time! 5:00pm This is a valid time! ,8:30AM

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://921034]
help
Chatterbox?
[erix]: I recognise the makings of a fine argument
[LanX]: lanx wonders ... how likely is it to talk >95% BS without intention?
[erix]: "gigantic amounts of data" is also not SQLite (imho)
talexb wonders why sqlite2 was deprecated in favour of sqlite3.
[erix]: looks like a fork, rather, no?
LanX /me /me
[erix]: /hehehe
[marto]: LanX yesterday I found out about Gish gallop tactic

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2017-07-28 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (431 votes). Check out past polls.