user759885
user759885

Reputation:

VB.NET Match string between parentheses (brackets)

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

Upvotes: 3

Views: 9427

Answers (1)

David B
David B

Reputation: 2698

\((.*?)\)

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

Upvotes: 6

Related Questions