First, a little background. I have strings that resemble the following:
((Foo.Bar.StartsWith("A")) && (Foo.Bar.EndsWith("B")))
And I'm trying to reformat these to look like this:
((Foo.Any(Bar.StartsWith("A"))) && (Foo.Any(Bar.EndsWith("B"))))
Side Note: The parts following the .Bar may sometimes not include (), like .Bar == "AB" .
I'm trying to capture two groups: the Foo. and the Bar.StartsWith("<A or B>") . I worked out the following pattern but it drops the trailing parenthesis.
\((Foo\.)(.*?)\)
So instead of getting what I'm looking for, I'm getting:
((Foo.Any(Bar.StartsWith("A")) && (Foo.Any(Bar.EndsWith("B")))
Which is two parentheses short.
The problem is I need to include closing parentheses in the .*? match IF there's also an opening parenthesis in there. I haven't figured out how to do this, anyone know?
PS - The code is C#.NET but that shouldn't matter unless the solution involves some obscure language-specific RegEx stuff.