再改一下10楼的用命名组合并到一条正则里,不用过两次了- $r='(?<a>\n\s*)(private|public|static|async|(?<b>(\b\S+|\([^()]+\))\s*))*(?<c>class\s+cs\s*(\([^)]*\))*\s*\{(?>[^{}\/\x22\x27]+(?<d>cd|abc)(\s*\([^)]*\))*|[^{}\/\x22\x27]+|\/\/[^\n]+|/\*(\n|.)*?\*/|[\x22\x27](\n|.)*?[\x22\x27]|[^{}]|\{(?<DEPTH>)|\}(?<-DEPTH>))*?(?(DEPTH)(?!))\})'
- [regex]::Matches($s, $r).groups|?{$_.name -eq 'd'}|%{$_.captures.value}
复制代码
|