gpt4 book ai didi

regex - 如何在 TCL/EXPECT 中使用 $expect_out 分配变量?

转载 作者:行者123 更新时间:2023-12-04 05:55:14 26 4
gpt4 key购买 nike

如果我想匹配 DEF_23使用以下正则表达式:

expect {
-re "DEF_\[0-9]*"
set result $expect_out(1,string)
}

为什么说 no such element in array ?
怎么样 $expect_out工作,以及如何捕获 DEF使用正则表达式并将其分配给变量 result ?

最佳答案

您正在寻找 expect_out(0,string) -- 数组元素1,string如果您在正则表达式中捕获括号,则会填充。

expect manpage 的文档中记录了expect_out 的使用。期待 命令:

Upon matching a pattern (or eof or full_buffer), any matching and previously unmatched output is saved in the variable expect_out(buffer). Up to 9 regexp substring matches are saved in the variables expect_out(1,string) through expect_out(9,string). If the -indices flag is used before a pattern, the starting and ending indices (in a form suitable for lrange) of the 10 strings are stored in the variables expect_out(X,start) and expect_out(X,end) where X is a digit, corresponds to the substring position in the buffer. 0 refers to strings which matched the entire pattern and is generated for glob patterns as well as regexp patterns.



联机帮助页中有一个说明性示例。

关于regex - 如何在 TCL/EXPECT 中使用 $expect_out 分配变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11051393/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com