I am working on a script to parse a certain fault code out of a SOAP message using tcl, and I have finally come to the part where I compare the message to the desired message. As you can see, I am trying to check if the string “9000” is contained in the array element “$soap(Fault)”
if { [ string match *\<FaultCode\>9000\</FaultCode\>* $soap(Fault) ] } {
# -- Success case
} else {
# -- fail case
}
In the example I have provided, I have escaped all of the “special characters” in tcl:
&;`'"|*?~<>^()[]{}$\
but is it required? Could one simply do:
*<FaultCode>9000</FaultCode>* ?
I have looked around pretty thoroughly and haven’t been able to find something quite as precise as what I am asking. I was going to ask in the tcl chat room, but I couldn’t find one!
Thanks
The short answer is that no, you don’t need to escape all those characters. In fact, some of those characters aren’t even special.
There are two layers here: first, at the tcl parsing level: reading through tcl’s parsing rules, you have a few options:
All of that is just determining what gets passed to [string match] – the second layer involves how [string match] deals with this pattern (it’s not a regex, by the way, it’s just a glob-style pattern). There are only these special characters in tcl’s glob style patterns: *, ?, [], . If you want any of these to be treated as literals, you have to escape them. Anything else is treated as a literal match, so you don’t have to worry about the <>’s, or the /.
So, this line is fine:
But you could also use these styles to set off the match pattern, stylistically.