Regex to capture text block

Asked

Viewed 235 times

1

I need to extract blocks of text that are inside #Regions:

#region VARIAVEIS GLOBAIS
string aux1 = "teste";
string aux2 = "teste2";
...
#endregion

The return would be:

string aux1 = "teste";
string aux2 = "teste2";
...

How do I do it with Regex?

Remembering that each Gion has a different name.

1 answer

1


I’m not a C# developer but this regular expression solves this problem, you need to see how it would look in your code:

(?<=#region VARIAVEIS GLOBAIS).*?(?=#endregion)

Example: https://regex101.com/r/wF5pE9/1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.