Rx找到匹配的括号 [英] Rx to find matching parenthesis
本文介绍了Rx找到匹配的括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何编写匹配的括号?
用于以下表达式:
sin(30)+(1 + 2)
正则表达式只能找到罪(30),不是整个字符串,sin ( 30)+(1 + 2 )。
"30"+(1 + 2"括号内的这个字符串没有匹配的括号。
要获得功能部分我需要正则表达式匹配括号。
< hr class ="sig"> MCSD .NET,SCJP,SCJWD
How can I write matching parenthesis?
for the following expression.
sin(30) + (1 + 2)
Regex should find only sin(30) ,
not the whole string, sin(30) + (1 + 2) .
"30) + (1 + 2" this string inside the parenthesis doesn't have matching parenthesis.
To get only function part I need regular expression matching parenthesis.
MCSD .NET, SCJP, SCJWD
推荐答案
你想使用非贪婪的算子。
" \(。+?\)"应该在括号内为你匹配。
当你有嵌套的括号时,我还没有找到方法。那就是更复杂,我不相信可以使用正则表达式来处理嵌套的括号,但是我给你的是应该为此工作。
You'd want to use a non-greedy operator.
"\(.+?\)" should get matches for you within parenthesis.
I haven't found a way yet when you have nested parenthesis, however. That'd be far more complicated, and I don't believe it'd be possible to use a regular expression to handle nested parenthesis, but what I gave you should work for this.
这篇关于Rx找到匹配的括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文