I’m trying to construct a regular expression that would extract the name of the structure, although I’m not finding anything with it. The steps I’m working through are:
- Look for the string ‘public struct’.
- Find all characters A-Z a-z one or more times and group them.
- Then look for line feed, carrige return or any other character one or more times (I think this would account for the opening curly bracket and the possibility of any spaces).
- Finally look for a }
/
public struct ABC{
int a;
int b;
}
public struct DEF {
ulong d;
string e;
}
Regex:
public struct ([A-Za-z]+)[{|\r|\n|.]+}
Should give:
ABC
DEF
Why is the regular expression not finding anything?
Because the body contains more than what can be matched by
[{|\r|\n|.]+.If you only want the name you can just use:
[{|\r|\n|.]+is the same as[{\r\n.|]+(brackets are a character class, not a group), you probably meant[^}]+.