【发布时间】:2012-03-01 10:22:16
【问题描述】:
我正在尝试在一个交互会话期间在同一屏幕输出上执行多个正则表达式匹配。使用以下代码,我收到错误消息:"cannot use -o more than once"
最终,我想使用this question 中详述的几个正则表达式从每个输出屏幕中提取几个小数据变量。我正在尝试做的事情是否可能,如果是,正确的语法是什么?
interact {
#...
#... actions during interact loop to perform with variables extracted
#...
#variable extraction from output ------------------------------------
-o -nobuffer -re {(\[1;14H[a-zA-Z0-9]{1})[0-9]{5}} {
#get po number
set poraw $interact_out(0,string)
#get just po out
set po [string range $poraw 6 11]
#switch to lowercase
set po [string tolower $po]
#send_user " stored po: $po"
}
#get cost from po detail
#ex. 001b[14;27H 20.1900
-o -nobuffer -re {(\[14\;27H)[0-9]{0-6}\.{1}[0-9]{4}} {
set pocost $interact_out(0,string)
send_user " stored po cost: $pocost"
}
}
编辑: 所以有效的代码如下所示:
interact {
#...
-o
-nobuffer -re {(\[1;14H[a-zA-Z0-9]{1})[0-9]{5}} {
#get po number
set poraw $interact_out(0,string)
#get just po out
set po [string range $poraw 6 11]
#switch to lowercase
set po [string tolower $po]
}
#get cost from po detail
#ex. 001b[14;27H 20.1900
-nobuffer -re {(\[14\;27H) *[0-9]{0,6}\.{1}[0-9]{4}} {
set pocostraw $interact_out(0,string)
set pocosttrim [string range $pocostraw 7 17]
set pocost [string trimleft $pocosttrim ]
send_user " stored po cost: $pocost"
}
}
【问题讨论】:
标签: regex linux scripting tcl expect