【问题标题】:TCL Regex ignore/parse leading asterisks in stringTCL 正则表达式忽略/解析字符串中的前导星号
【发布时间】:2019-12-11 00:58:58
【问题描述】:

我正在尝试编写一个期待这样的字符串:

*** error doing something

我目前使用的 tcl 代码如下:

expect {
    -re "*** error doing something\[\r\n\]" {
        puts $log "$expect_out(buffer)"
        return 1
    }
}

但是字符串不匹配。我认为这取决于 * 特殊字符。我无法更改错误输出,因此我必须更改正则表达式解析以忽略“***”或正确解析它。

我该怎么做?

【问题讨论】:

    标签: regex tcl


    【解决方案1】:

    * 是正则表达式中的量词,因此如果您希望它们表示实际的星号,则需要对其进行转义。您可能希望使用大括号来避免额外的转义:

    expect {
        -re {\*\*\* error doing something\[\r\n\]} {
            puts $log "$expect_out(buffer)"
            return 1
        }
    }
    

    免责声明:我不熟悉expect

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      相关资源
      最近更新 更多