Using glob to search for wildcard numbers such as FIBRENNNN where NNNN=1235 for example

From: Jonathan Smoker (jonathan_smoker_at_hotmail.com)
Date: 12/29/03


Date: 29 Dec 2003 09:11:03 -0800

Hello,

Sorry, this is an easy tcl question from someone just starting. I am
using tcl to search through a file, looking for the following type of
strings;

FIBRE1149
FIBRE2052
FIBRE1235

-where 'FIBRE' is always the same, just the four digits of the
following number change. The manual says that I can just use 'glob'
with the same arguments that 'string match' also uses, viz something
like [0-9].

My script works fine if I just use FIBRE (as in the code segment shown
at the bottom), but I can't seem to get the syntax right to make it
search for FIBRENNNN. Could anyone please advise me what I am doing
wrong?. I have tried the following variants;

set key_fibre_N [lsearch -glob FIBRE[0-9][0-9][0-9][0-9] $key] - wrong
syntax
set key_fibre_N [lsearch -glob FIBRE[????] $key] - wrong syntax
set key_fibre_N [lsearch -glob [FIBRE????] $key] - wrong syntax

set key_fibre_N [lsearch -glob FIBRE???? $key] -
syntax OK but I think looks for FIBRE???? which is no good
set key_fibre_N [lsearch -glob {FIBRE[0-9][0-9][0-9][0-9]} $key] -
syntax OK but does not find FIBRE1234
set key_fibre_N [lsearch -glob {[FIBRE][0-9][0-9][0-9][0-9]} $key] -
syntax OK but does not find FIBRE1234

Code segment that I have written;

while {![eof $fidin]} {
    set inline [gets $fidin]
    set inline_split [split $inline]

    foreach key [split $inline] {
        set count_0 [expr $count_0 + 1]
        set count_1 [expr $count_0 + 1]
        set key_fibre_N [lsearch -glob FIBRE $key]
        puts $key_fibre_N
        puts $key
    }
}
close $fidin
close $fidout

Thanks!,
 Jonathan.



Relevant Pages

  • Re: Performance of REGEXP_LIKE vs LIKE?
    ... There are certain situations where the syntax of REGEXP_LIKE ... is cleaner and shorter than the comparable LIKE expression. ... search of a 3 million record table, for a series of text strings. ... How about Oracle Text? ...
    (comp.databases.oracle.misc)
  • Re: Proposal for adding symbols within Python
    ... I don't like any syntax I've seen so far, but I can understand the problem. ... (Rather than a string used as a key in that namespace) ... Often you can use strings for that sort of thing, ... The reason I'm more interested in seeing usecases, ...
    (comp.lang.python)
  • Re: Array difference
    ... is there any logical reason why the language doesn't ... but they plan on having a syntax like this. ... use the initialization syntax for the String array. ... Which declares that the method accepts a variable number of strings. ...
    (comp.lang.java.programmer)
  • Re: Cantors definition of set
    ... Not the definition of ordered pair, ... at the level of distinguishing syntax from semantics. ... of set theory is strings of symbols, ... subsequent ones would be squares. ...
    (sci.logic)
  • Re: switch(true) in c#
    ... switch statements evaluate strings, they don't work on boolean variables. ... have a look at the syntax for it in the helpfile and work your code ...
    (microsoft.public.dotnet.framework.aspnet)