how to use regexp to match a parentheses in TCL

妖精的绣舞 提交于 2019-12-24 00:56:12

问题


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


来源:https://stackoverflow.com/questions/14237376/how-to-use-regexp-to-match-a-parentheses-in-tcl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!