**
题目:
查找文本中的关键字:编写一个脚本,读取一个文本文件,查找其中出现的某个关键字,并输出包含该关键字的行数和内容。
set in_file [open "./in.f" r]
set out_file [open "./out.f" w]
set i 0
while {[gets $in_file line] != -1} {
incr i
if { [regexp {\w+\d+reg[0-3]} $line] == 1} {
puts $out_file "line $i 's content is $line"
}
}
close $out_file
chatGPT给出的答案是使用string match ,仅适用于字符串,使用正则匹配使用范围更广
**