在变量值"52/80"中搜索子字符串"52"在 TCL 中不起作用



我正在使用的代码:

set channel 52/80   
if {![ regexp { ([0-9]+)/80 } $channel match cchannel ] } {
puts "Channel regex-ed in [SLVR][SetAffected_channels] is: $cchannelnn"
}

返回错误:无法读取"cchannel":没有这样的变量

我在这里错过了什么吗?

由于多余的空格,您的代码不匹配。

% set channel 52/80   
52/80
% regexp { ([0-9]+)/80 } $channel match cchannel
0
% regexp {([0-9]+)/80} $channel match cchannel
1
% set match
52/80
% set cchannel
52

在这种情况下,您也不应该反转regexp的结果;if正文脚本似乎适用于模式匹配的情况......

最新更新