Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

regexp for glob
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

Report this thread to moderator Post Follow-up to this message
Old Post
Laurent Duperval
08-27-04 01:58 AM


Re: regexp for glob

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


Report this thread to moderator Post Follow-up to this message
Old Post
Bruce Hartweg
08-27-04 01:58 AM


Re: regexp for glob
On 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



Report this thread to moderator Post Follow-up to this message
Old Post
Laurent Duperval
08-27-04 08:57 AM


Re: regexp for glob
Laurent 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Donal K. Fellows
08-27-04 01:58 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:48 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.