回复 9# idwma
现在输出如下, 但是我只需要红色字部分
public static void Main()
{
string s = "xzc abc(s \"(abc)\")); dfg()";
string p = @"}";
string q = @"}{{";
string[] result = matches(s, p);
}
public static void Main()
{
string s = "xzc abc(s \"(abc)\")); dfg()";
string p = @"}";
string q = @"{{}";
string[] result = matches(s, p);
}
--------------------------
public static void Main()
{
string s = "xzc abc(s \"(abc)\")); dfg()";
string p = @"}";
string q = @"{{}";
string[] result = matches(s, p);
}- $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>\r?\n\s*)(private|public|static|async|(?<b>(\b\S+|\([^()]+\))\s*))*(?<c>' + $b + '\s*(\([^)]*\))*\s*\{(?>(?<d>(\r?\n\s*)(private|public|static|async|(?<b>(\b\S+|\([^()]+\))\s*))*(?<c>' + $a + '\s*(\([^)]*\))*\s*\{(?>[^{}\/\x22\x27]+|\/\/[^\n]+|/\*(\r?\n|.)*?\*/|[\x22][^\x22]*[\x22]|[\x27][^\x27]*[\x27]|[^{}]|\{(?<DEPTH>)|\}(?<-DEPTH>))*?(?(DEPTH)(?!))\}))|[^{}\/\x22\x27]+|\/\/[^\n]+|/\*(\r?\n|.)*?\*/|[\x22\x27](\r?\n|.)*?[\x22\x27]|[^{}]|\{(?<DEPTH>)|\}(?<-DEPTH>))*?(?(DEPTH)(?!))\})'
- [regex]::Matches($s, $r).groups | ?{ $_.name -eq 'd' } | %{ $_.captures.value }
- }
-
- getFuncText -a "Main"
- "--------------------------"
- getFuncText -a "Main" -b "zz"
复制代码
|