The Enum I want to extract is like following:
...
other code
...
enum A
{
a,
b=2,
c=3,
d//{x}
}
...
More Enums like the above.
...
First, I have tried using the Option Singleline
with Regex:
enum\s*\w+\s*{.*?\}
However, since the comments have brackets.The regex doesn't work. It will stop when it runs to the bracket in comments.
So I tried excluding the bracket after comments. Based on what I have searched so far,it seems I need Negative look ahead with grouping construct Multiline
.
Then I tried parsing the brackets without comments ahead.
The substep is to find brackets after comments:
(?m:^.*?//.*?}.*?$)
.
However, it seems the .
still match anychar including newline even in inline multiline mode.
Then I tried using multiline in the first place. Since the main problem is the brackets in comments.I tried:
(?!//.*)}
Negative look ahead doesn't work the way I expected.
Here is a csharp-regex-test-link for you to test.
To summarize, I need parse enum from a csharp source code file.
The main problem to me is the brackets in comments.
Edit: To clarify
1.brackets in comments are in pairs. For example:
xxx=xxx; //{xx}
2.comments are only in the form of //
3.I can't rely on indentations.