File::glob pattern matching

Discussion in 'Perl Misc' started by bjlockie, Jun 22, 2012.

  1. bjlockie

    bjlockie Guest

    I tried [[:digit:]] which is posix but doesn't work.
    I know ? matches any single character but I only want to match exactly 2 digits.
    bjlockie, Jun 22, 2012
    #1
    1. Advertising

  2. bjlockie <> writes:
    > I tried [[:digit:]] which is posix but doesn't work.
    > I know ? matches any single character but I only want to match
    > exactly 2 digits.


    [0-9][0-9]

    should do the trick (if you're happy with standard 'western/ arabic'
    numbers).
    Rainer Weikusat, Jun 22, 2012
    #2
    1. Advertising

  3. On Fri, 22 Jun 2012 20:54:54 +0100, Rainer Weikusat wrote:

    > bjlockie <> writes:
    >> I tried [[:digit:]] which is posix but doesn't work.
    >> I know ? matches any single character but I only want to match exactly
    >> 2 digits.

    >
    > [0-9][0-9]
    >
    > should do the trick (if you're happy with standard 'western/ arabic'
    > numbers).


    or [0-9]{2}, or [[:digit:]]{2}.

    M4
    Martijn Lievaart, Jun 22, 2012
    #3
  4. On Fri, 22 Jun 2012 22:33:01 +0100, Ben Morrow wrote:

    > Quoth Martijn Lievaart <>:
    >> On Fri, 22 Jun 2012 20:54:54 +0100, Rainer Weikusat wrote:
    >>
    >> > bjlockie <> writes:
    >> >> I tried [[:digit:]] which is posix but doesn't work.
    >> >> I know ? matches any single character but I only want to match
    >> >> exactly 2 digits.
    >> >
    >> > [0-9][0-9]
    >> >
    >> > should do the trick (if you're happy with standard 'western/ arabic'
    >> > numbers).

    >>
    >> or [0-9]{2}, or [[:digit:]]{2}.

    >
    > The OP is using globs, not regexes.


    Oopsie.

    M4
    Martijn Lievaart, Jun 23, 2012
    #4
  5. bjlockie

    Marc Girod Guest

    On Jun 22, 10:33 pm, Ben Morrow <> wrote:

    > > or [0-9]{2}, or [[:digit:]]{2}.

    >
    > The OP is using globs, not regexes.


    But {2} is explicitly supported in File::Glob, and also works in
    CORE::glob:

    tmp> touch aa12bb
    tmp> perl -le '@f=glob(q(aa[0-9]{2}bb));print for @f'
    aa12bb

    Now, it is correct that [[:digit::]] doesn't work (and should?)

    tmp> perl -M'File::Glob qw:)glob)' -le \
    '@f=glob(q(aa[[:digit:]]{2}bb));print for @f'

    Marc
    Marc Girod, Jun 23, 2012
    #5
  6. bjlockie

    Marc Girod Guest

    On Jun 23, 7:37 pm, Marc Girod <> wrote:

    > Now, it is correct that [[:digit::]] doesn't work (and should?)


    tmp> ls aa[[:digit:]][[:digit:]]bb
    aa12bb
    tmp> ls aa[[:digit:]]{2}bb
    ls: cannot access aa[[:digit:]]{2}bb: No such file or directory

    I meant that [[:digit:]] works with ls, but {2} doesn't

    Marc
    Marc Girod, Jun 23, 2012
    #6
  7. bjlockie

    Marc Girod Guest

    On Jun 23, 9:40 pm, Ben Morrow <> wrote:

    > It doesn't do what you think it does. Try aa13bb.


    Indeed:

    tmp> perl -le '@f=glob(q(aa[0-9]{2,3}bb));print for @f'
    aa12bb
    aa13bb

    I didn't read with enough attention... and I missed the fact that
    the following was ambiguous, and only explained later:

    {} Multiple pattern

    > A strict reading of SUSv4 actually says it should, to my surprise,
    > but traditional shells didn't support it. (On my system the only
    > shell which does is bash, as might be expected.)


    That's the only one I tried...
    Thanks.

    Marc
    Marc Girod, Jun 24, 2012
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Georgy Pruss
    Replies:
    15
    Views:
    723
    Tim Roberts
    Dec 1, 2003
  2. Tim Peters
    Replies:
    1
    Views:
    356
    Duncan Booth
    Dec 1, 2003
  3. Sean Berry

    Question about glob.glob <--newbie

    Sean Berry, May 4, 2004, in forum: Python
    Replies:
    3
    Views:
    345
    David M. Cooke
    May 4, 2004
  4. Elbert Lev

    glob.glob unicode bug or feature

    Elbert Lev, Jul 31, 2004, in forum: Python
    Replies:
    5
    Views:
    392
    Neil Hodgson
    Aug 2, 2004
  5. qanda
    Replies:
    1
    Views:
    110
    Tassilo v. Parseval
    Sep 15, 2003
Loading...

Share This Page