regex - matching regular expression {*} in tcl -


i trying match name plus possible suffix using {*} regular expression in tcl script. example:

#!/usr/bin/tclsh set name "g_renamed_d" set pattern "g_renamed*" if {  [string match "$name" "$pattern"]} {     puts " matched!"  } else {     puts " not matched!!!!!" } 

when did not work tried removing star pattern variable , using [string match "$name" "$pattern"*] or [string match $name $pattern*] or [string match $name {$pattern*}] no avail. have seen other examples seem identical did; missing?

you can try syntax:

#!/usr/bin/tclsh set name "g_renamed_d" set pattern "^g_renamed.*" if {[regexp $pattern $name match]} {     puts " matched! :)"      puts $match } else {     puts " not matched! :(" } 

note pattern above allows kinds of characters including white spaces except newlines. if want more "reasonable" pattern, can replace comma character class characters allow in suffix:

set pattern "^g_renamed[a-z0-9_]*" # "word" character (the same \w) 

or

set pattern "^g_renamed\s*"    # not white space 

but pattern suffisant if want check string begins target:

set pattern "^g_renamed" 

Comments