Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, Is there a way to glob for file names that start with a lower-case character, followed by three or more letters then ends with four or more digits? Hence, mathing would yield: foobar123456.txt = true foo123456.txt = false foobar_123456.txt = false fooBar123456.txt = false foobar123.txt = false I know how to do it with regexp but how about glob? I guess I could get all the files then match them with a regular expression but that seems like overkill to me. L
Post Follow-up to this message
Laurent Duperval wrote:
> Hi,
>
> Is there a way to glob for file names that start with a lower-case
> character, followed by three or more letters then ends with four or more
> digits? Hence, mathing would yield:
>
> foobar123456.txt = true
> foo123456.txt = false
> foobar_123456.txt = false
> fooBar123456.txt = false
this one seems to match you description. or do you mean ALL letters must be lower case[colo
r=darkred]
> foobar123.txt = false
>
> I know how to do it with regexp but how about glob? I guess I could get
> all the files then match them with a regular expression but that seems
> like overkill to me.
>[/color]
if you have "... or more" in you verbal description you can't do it
with glob, because the only multi char match is * which matches any number
of *any* chars. you will need an RE to do this fully. if there are
a large number of files, you could do a special glob that will prune
out some & then do a final check with the RE
if you meant all lower case letters (4+ lc chars, followed by 4+ digits)
set glob {[a-z][a-z][a-z][a-z]*[0-9][0-9][0-9][0-9]*}
set RE {^[a-z]{4,}[0-9]{4,}\.}
if only the first char needs lower cased
set glob {[a-z][a-zA-Z][a-zA-Z][a-zA-Z]*[0-9][0-9][0-9][0-9]*}
set RE {^[a-z][a-zA-Z]{3,}[0-9]{4,}\.}
foreach name [glob $glob] {
if [regexp $RE $name] {
lappend fileList $name
}
}
Bruce
Post Follow-up to this messageOn Thu, 26 Aug 2004 18:19:49 -0500, Bruce Hartweg wrote:
> this one seems to match you description. or do you mean ALL letters must be lower
case
All must be lower case. Sorry.
> if you have "... or more" in you verbal description you can't do it
> with glob, because the only multi char match is * which matches any number
> of *any* chars. you will need an RE to do this fully. if there are
> a large number of files, you could do a special glob that will prune
> out some & then do a final check with the RE
>
That's what I thought.
>
> if you meant all lower case letters (4+ lc chars, followed by 4+ digits)
>
> set glob {[a-z][a-z][a-z][a-z]*[0-9][0-9][0-9][0-9]*}
> set RE {^[a-z]{4,}[0-9]{4,}\.}
>
Thanks, that'll save me from actually figuring out the RE.
L
Post Follow-up to this messageLaurent Duperval wrote: > I know how to do it with regexp but how about glob? I guess I could get > all the files then match them with a regular expression but that seems > like overkill to me. Glob-matching just isn't that powerful (which helps keep it fast) but you could use it to pre-filter the filenames to remove obvious failures before the final check with RE. Donal.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.