C# 正则表达式匹配表达式中的偶数括号
我有以下表达式:
KNOWN_TOKEN=((value operator value) operator value)
operator OTHER_KNOWN_TOKEN=value
operator KNOWN_TOKEN2=(value operator (value operator value));
我试图找到 ac# 正则表达式,以在打开时返回带有相等匹配的闭括号的整个表达式。这意味着,对于 KNOWN_TOKEN
我只需要 ((value operator value) operator value)
,对于 OTHER_KNOWN_TOKEN
我只需要 value
code> 对于 KNOWN_TOKEN2
我需要 (值运算符(值运算符值))
。
我尝试了各种风格的 (\([^(]+\))
但它们只匹配“最低”的“括号”组,此外,它们还匹配一个额外的组(即 KNOWN_TOKEN2
它们匹配一个额外的结束括号)。
另外,我在网上找到了一些关于将其分成几个重复步骤并更改原始文本的提示,但我宁愿将其放入一个正则表达式中。提示?
谢谢!
I have the following expressions:
KNOWN_TOKEN=((value operator value) operator value)
operator OTHER_KNOWN_TOKEN=value
operator KNOWN_TOKEN2=(value operator (value operator value));
I am trying to find a c# regular expression to return me the entire expression with equally matched closed parenthesis as they were opened. This means, for KNOWN_TOKEN
I need only ((value operator value) operator value)
, for OTHER_KNOWN_TOKEN
I need only value
and for KNOWN_TOKEN2
I need (value operator (value operator value))
.
I tried various flavours of (\([^(]+\))
but they only match the 'lowest' set of 'paranthesis' and in addition, they match an extra one (i.e. for KNOWN_TOKEN2
they match an extra ending parenthesis).
Also, I have found some hints on the web on doing it into several repeating steps and alter the original text, but I'd rather do it into one single regexp. Any hints?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已编辑
EDITED