Re: regex question matching dates



Richard Lee wrote:
given then ARGV[0] is 2008052803, why woulnd't below regex match them??

2008052803 is a ten digit number.


} elsif ( $ARGV[0] =~ m/\b2008[01][1-31]([01][0-9]|2[0-3])\b/ ) {

Your pattern matches eight digits with a \b word boundary at each end so it will never match a ten digit number. Also the character class [1-31] could be more simply written as [1-3] (repeated characters are ignored.)


@array = qx#ls -tr $directory/$ARGV[0]*#;

Why not do that directly in perl:

@array = map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, -M ], glob "$directory/$ARGV[0]*";


#2008052803


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.



Relevant Pages

  • Re: regex question matching dates
    ... Richard Lee wrote: ... Your pattern matches eight digits with a \b word boundary at each end so it will never match a ten digit number. ... can special-order certain sorts of tools at low cost and ...
    (perl.beginners)
  • Re: Help with a regex pattern please
    ... merge them together so that the pattern will look for three digits ... you will only match the digits, and not the subsequent period. ... within a character class. ...
    (microsoft.public.excel.programming)
  • Re: Help with regexp. Can you do better
    ... character class. ... Each of those is searching for one or more digits, ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: find and regular expresions
    ... That matches only if there are exactly 3 digits in each substring. ... regex-ified grep to which you can pipe the output of find (grep is ... huge set of pattern matches that will do the job. ...
    (comp.unix.shell)
  • Re: data regex match
    ... by a byte with the ASCII value 1, followed by a slash, followed by two ... bytes with the ASCII value 1. ... that pattern matches two digits, followed by a slash, ...
    (comp.lang.python)