Matching open / close symbols in pairs in regular expressions

Firstly, a little background. I have lines that resemble the following:

((Foo.Bar.StartsWith ("A")) && & (Foo.Bar.EndsWith ("B")))

And I'm trying to reformat them like this:

((Foo.Any (Bar.StartsWith ("A"))) && & (Foo.Any (Bar.EndsWith ("B"))))

Side note. Parts following .Bar may sometimes not include (), for example .Bar == "AB".

I am trying to capture two groups: Foo. and Bar.StartsWith ("<A or B>"). I developed the following pattern, but it resets the sliding bracket.

\((Foo\.)(.*?)\)

So instead of getting what I'm looking for, I get:

((Foo.Any (Bar.StartsWith ("A")) && & (Foo.Any (Bar.EndsWith ("B")))

.

, . *? , . , , - ?

PS. - #.NET, , - RegEx.

+2
1

, ? "" , .

. , "(Foo.", , , . , ( , ). , - 0, , . , Any(), . "(Foo.".

? , , , . , , .

+4

Source: https://habr.com/ru/post/1737006/


All Articles