-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathClass.regex.txt
23 lines (23 loc) · 1.84 KB
/
Class.regex.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Matches a CSharp class
(?<AccessModifier>(?:(?-i) (?>
protected\s{1,}internal |
protected |
private\s{1,}protected |
internal |
private |
public)?)) # An Optional Access Modifier
\s{1,}(?:(?-i)class\s{1,}) # Followed by 'class'
(?<ClassName>[\p{L}_][\p{Pc}\p{L}\d\p{Mn}]{0,}) # Followed by an identifier
(?:\s{1,}(?<IsInheriting>\:)\s{1,})? # Followed by an optional colon
# If a colon was present, followed by a number of identifiers
(?(IsInheriting)((?:(?:\s{0,} (?<Inherits>[\p{L}_][\p{Pc}\p{L}\d\p{Mn}]{0,})\s{0,}\,{0,})){1,}))\s{0,} # Followed by whitespace and balanced curly brackets
(?<ClassBody>(?<BalancedCurlyBracket>
\{ # An open {
(?> # Followed by...
[^\{\}]+| # any number of non-bracket character OR
\{(?<Depth>)| # an open curly bracket (in which case increment depth) OR
\}(?<-Depth>) # a closed curly bracket (in which case decrement depth)
)*?(?(Depth)(?!)) # until depth is 0.
\} # followed by a }
)
)