回复 2# idwma
多谢大佬, 试了一下, 没有输出- $s = @'
- using System;
-
- public class xx
- {
- public static void Main()
- {
- string s = "xzc abc(s \"(abc)\")); dfg()";
- string p = @"}";
- string q = @"}{{";
- string[] result = matches(s, p);
- }
-
- public static string hello(string s, string p)
- {
- Match match = Regex.Match(s, p);
- string fullMatch = match.Value;
- }
- }
-
- public class zz
- {
- public static void Main()
- {
- string s = "xzc abc(s \"(abc)\")); dfg()";
- string p = @"}";
- string q = @"{{}";
- string[] result = matches(s, p);
- }
-
- public static string hello(string s, string p)
- {
- Match match = Regex.Match(s, p);
- string fullMatch = match.Value;
- }
- }
- '@
-
- function getFuncText($a, $b)
- {
- if (!$b) { $b = '\S+' }
- $r = '(?<a>\n\s*)(private|public|static|async|(?<b>(\b\S+|\([^()]+\))\s*))*(?<c>' + $b + '\s*(\([^)]*\))*\s*\{(?>(?<d>(\n\s*)(private|public|static|async|(?<b>(\b\S+|\([^()]+\))\s*))*(?<c>' + $a + '\s*(\([^)]*\))*\s*\{(?>[^{}\/\x22\x27]+|\/\/[^\n]+|/\*(\n|.)*?\*/|[\x22][^\x22]*[\x22]|[\x27][^\x27]*[\x27]|[^{}]|\{(?<DEPTH>)|\}(?<-DEPTH>))*?(?(DEPTH)(?!))\}))|[^{}\/\x22\x27]+|\/\/[^\n]+|/\*(\n|.)*?\*/|[\x22\x27](\n|.)*?[\x22\x27]|[^{}]|\{(?<DEPTH>)|\}(?<-DEPTH>))*?(?(DEPTH)(?!))\})'
- [regex]::Matches($s, $r).groups | ?{ $_.name -eq 'd' } | %{ $_.captures.value }
- }
-
- getFuncText -a "Main"
- "--------------------------"
- getFuncText -a "Main" -b "zz"
复制代码
|