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

Using lsearch to match on a string.
Hello, I am trying to use lsearch to match on a string value to check
to see if the string has any numeric elements in it.
ex. set fund_number [csubstr $msg 181 5]
set numeric [lsearch -regexp $fund_number *A-Z* ], it tells me that
quantifier operand invalid. I can not figure out what I'm doing wrong,
please help thanks.

Report this thread to moderator Post Follow-up to this message
Old Post
Derrick Cottner
08-23-04 09:01 PM


Re: Using lsearch to match on a string.
Derrick Cottner wrote:

> Hello, I am trying to use lsearch to match on a string value to check
> to see if the string has any numeric elements in it.
> ex. set fund_number [csubstr $msg 181 5]
> set numeric [lsearch -regexp $fund_number *A-Z* ], it tells me that
> quantifier operand invalid. I can not figure out what I'm doing wrong,
> please help thanks.

Does csubstr return a list? lsearch is to be used only on lists; if you
use it on a string and that string isn't a well formed list, the command
will fail.  You will also get unexpected results if the string looks
like a multi-element list rather than a single element.

But on to your question... * is a quantifier; that is, it quantifies the
subexpression before it. * means "zero or more of the preceeding
subexpression". The leading * has no preceeding subexpression which is
why you get the error.

It looks like you're thinking about glob patterns rather than regular
expressions, and for that you can use "string match". Given that you
appear to be trying to match to a string anyway that seems better way to
go than to persist in trying to make lsearch work.

Try this and see if it does what you want:

set numeric [string match {*[A-Z]*} $fund_number]


Report this thread to moderator Post Follow-up to this message
Old Post
Bryan Oakley
08-24-04 01:58 AM


Re: Using lsearch to match on a string.
"Bryan Oakley" <oakley@bardo.clearlight.com> wrote in message
news:uWsWc.12252$sY3.7331@newssvr22.news.prodigy.com...
: Derrick Cottner wrote:
:
: > Hello, I am trying to use lsearch to match on a string value to check
: > to see if the string has any numeric elements in it.
: > ex. set fund_number [csubstr $msg 181 5]
: > set numeric [lsearch -regexp $fund_number *A-Z* ], it tells me that
: > quantifier operand invalid. I can not figure out what I'm doing wrong,
: > please help thanks.

[ ... lots of good advice snipped ... ]

: Try this and see if it does what you want:
:
:      set numeric [string match {*[A-Z]*} $fund_number]

I knew it was only a matter of time before Bryan would be all over this
one...   ;^)
As usual, great advice Bryan...

Jeff



Report this thread to moderator Post Follow-up to this message
Old Post
Jeff Godfrey
08-24-04 01:58 AM


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:47 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.