Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Regex problem.

Trying to create a regex that grabs the conditions and statements from if statements.

Currently I have this.
Code
if\((.*)\)[\r\n]*{[\r\n]*(.*)[\r\n]*}

But it only matches single line statements such as
Code
if(value >= 5)
{
DoSomething();
}

When I need it to match multi-line statements such as
Code
if(value >= 5)
{
DoSomething();
DoSomethingElse();
}

Been testing here any help would be much appreciated :)
[Image: giminur.gif]
This should work

Code
if\((.*)\)\n{([\r\n]*(.*)[\r\n])*}

Idk why you have [\r\n]* instead of just \n after if() pattern.
(Apr 12, 2017 09:31 AM)MasterCurser Wrote:  This should work

Code
if\((.*)\)\n{([\r\n]*(.*)[\r\n])*}

Idk why you have [\r\n]* instead of just \n after if() pattern.

Cheers, that worked perfectly (with a little bit of editing to make it non-greedy)

Code
if\((.*)\)[\r\n]*{([\r\n]*(.*)[\r\n])*?}
[Image: giminur.gif]
(Apr 12, 2017 09:35 AM)i3urn Wrote:  Cheers, that worked perfectly (with a little bit of editing to make it non-greedy)

Code
if\((.*)\)[\r\n]*{([\r\n]*(.*)[\r\n])*?}

Looks good. 🤝
Don't lexers omit whitespace and line breaks when parsing?


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by HardStoNMay 9, 2019 11:22 AM 2 91 May 9, 2019 11:22 AM
Last Post: HardStoN
[.NET] by WhatIsRSOct 31, 2016 07:51 PM 7 247 Oct 31, 2016 07:51 PM
Last Post: Ninja
[C#] by dark.teamOct 27, 2015 06:55 AM 3 82 Oct 27, 2015 06:55 AM
Last Post: dark.team