如何在正则表达式中使用变量(TCL/Expect) [英] How to use a variable in regexp expression (TCL/Expect)

查看:538
本文介绍了如何在正则表达式中使用变量(TCL/Expect)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何在正则表达式匹配中使用字符串.我已经在Google上搜索了一个小时,以为我只想问问专家.

I'm trying to figure out how to use a string in a regexp match. I have been searching on google for an hour, figured i would just ask the experts.

这有效:

#!/usr/bin/expect

set MYSTR "value"

if [ regexp -nocase "$MYSTR" $outcome matchresult ] then {
...
}

这不起作用:

#!/usr/bin/expect

set MYSTR "value"

if [ regexp -nocase {something here:\s+$MYSTR} $outcome matchresult ] then {
...
}

我确定这是一个简单的语法问题.

I'm sure it's a simple syntax problem.

感谢您的帮助

推荐答案

正确.您有2个选择:用"包围模式,但是必须保护T1而不是regxp解析\.或者,您可以使用regexp -nocase [subst -nocommands -nobackslashes {something here:\s+$MYSTR}].

Right. You have 2 options: enclose the pattern with " , but then you have to protect \ from being parsed by Tcl instead of the regxp. Or you can use regexp -nocase [subst -nocommands -nobackslashes {something here:\s+$MYSTR}].

PS:始终{} 放在 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆