I tried the following code:
set exp {elem[0]}
set temp {elem[0]}
regsub $temp $exp "1" exp
if {$exp} {
puts "######### 111111111111111 ################"
} else {
puts "########### 0000000000000000 ############"
}
of course, this is the easiest regsub possible (the words match completely), and still it doesnt work, and no substitution is done. if I write elem instead of elem[0], everything works fine.
I tried using {elem[0]}, elem[0], “elem[0]” etc, and none of them worked.
Any clue anyone?
Actually, no, the words don’t match. You see, in a regular expression, square brackets have meaning. Your expression
{elem[0]}actually mean:So it would match the string “elem0” not “elem[0]” since the character after ‘m’ is not ‘0’.
What you want is
{elem\[0\]}<– backslash escapes special meaning.Read the manual for tcl’s regular expression syntax, re_syntax, for more info on how regular expressions work in tcl.