VB.NET Match string between parentheses (brackets)

試著忘記壹切 提交于 2019-12-02 03:36:55

问题


Looking for a pattern for matching text between brackets. For example: "(this is) a (test)" should output

"this is"
"test"

Using Dim m As Match = Regex.Match(str, pattern, RegexOptions.Multiline)

I have searched stackOverflow, Google and tried examples on RegExr and nothing seems to work for me.

These work on RegExr but in not VB.NET

"\(([^)(]++|(?R))+\)" - error nested quantifier

"(?<=\<p\>)(.*?)(?=<\/p\>)" - quantifier following nothing

Others will return: "this is) a (test" - matching far outer brackets

PS I could also do with the same for

[],"",{}

it would be good to have them all in one place for anyone looking under vb.net


回答1:


\((.*?)\)

Your regex is very complicated! This one will grab all text in between two () and match the inner text. Play with it here.



来源:https://stackoverflow.com/questions/12101766/vb-net-match-string-between-parentheses-brackets

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