how to use regexp to match a parentheses in TCL

2019-07-10 09:28发布

问题:

I have a question about using regexp to match a parentheses in TCL.

For example I have a string like this:

yes, it is (true, and it is fine).

I just want to match this part yes, it is (true, how to match it?

回答1:

You can enclose parentheses in a character class as @bobah suggests,

yes, it is [(]true

But it's more common to escape it:

yes, it is \(true

But if you're escaping it, make sure you understand that you must either do this:

regexp -- "yes, it is \\(true" $subject

or this:

regexp -- {yes, it is \(true} $subject


标签: regex tcl expect