我正试图弄清楚如何在正则表达式匹配中使用字符串。我已经在谷歌上搜索了一个小时,我想我应该问问专家。
这项工作:
#!/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 {
...
}
我确信这是一个简单的语法问题。
感谢您的帮助
右侧。您有两个选项:用"
封装模式,但必须保护不被Tcl而不是regxp解析。或者您可以使用
regexp -nocase [subst -nocommands -nobackslashes {something here:s+$MYSTR}]
。
PS:始终将{}
放在表达式周围:
if {[regexp -nocase [subst -nocommands -nobackslashes {something here:s+$MYSTR}]} then {
...
}