File::glob pattern matching

B

bjlockie

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.
 
R

Rainer Weikusat

bjlockie said:
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).
 
M

Martijn Lievaart

bjlockie said:
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
 
M

Martijn Lievaart

Quoth Martijn Lievaart said:
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
 
M

Marc Girod

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
 
M

Marc Girod

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
 
M

Marc Girod

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top