Regexp and $
Hi All,
In my program I read expressions from a file. The expressions
have variables that are prefaced with a $ (like Tcl). Here’s an
example:
In my program I read expressions from a file. The expressions
have variables that are prefaced with a $ (like Tcl). Here’s an
example:
( $capacity == 1 )
I would like to use regsub to re-write the expression. However, I can’t
seem to match the pattern “$capacity” in the expression, if the pattern is
in a variable. The problem seems to be the dollar sign in the pattern.
Here are some things I’ve tried.
% set expr “( \$capacity == 1 )”
( $capacity == 1 )
% regexp \$capacity $expr
0
% regexp {\$capacity} $expr
1
% set var \$capacity
$capacity
% regexp $var $expr
0
% regexp ${var} $expr
0
I would like to be able to use match a pattern like $capacity when it is
stored in a variable like the example above. What am I doing wrong?
Thanks for any pointers.
David
Read more here: Source link
