如何使用regexp匹配TCL中的括号

2 regex tcl expect

我有一个关于使用regexp匹配TCL中括号的问题.

例如,我有一个这样的字符串:

yes, it is (true, and it is fine).
Run Code Online (Sandbox Code Playgroud)

我只是想匹配这部分yes, it is (true,如何匹配呢?

And*_*ong 5

你可以在@bobah建议的字符类中括起括号,

yes, it is [(]true
Run Code Online (Sandbox Code Playgroud)

但逃避它更常见:

yes, it is \(true
Run Code Online (Sandbox Code Playgroud)

但如果你逃避它,请确保你明白你必须这样做:

regexp -- "yes, it is \\(true" $subject
Run Code Online (Sandbox Code Playgroud)

或这个:

regexp -- {yes, it is \(true} $subject
Run Code Online (Sandbox Code Playgroud)