Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageDerrick 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]
Post Follow-up to this message
"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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.