如何使用regexp匹配TCL中的括号 [英] how to use regexp to match a parentheses in TCL

查看:869
本文介绍了如何使用regexp匹配TCL中的括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用regexp匹配TCL中的括号有疑问.

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).

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

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

推荐答案

您可以按照@bobah的建议,将字符括号括在字符类中,

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

或者这个:

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

这篇关于如何使用regexp匹配TCL中的括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆