[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
用下面的方法仍然不行
  1. $s = @'
  2. using System;
  3. using System.Text.RegularExpressions;
  4. public class cs
  5. {
  6.     public string cd(string s, string rx)
  7.     {
  8.         //cd
  9.     }
  10.     public static int abc(string s)
  11.     {
  12.         //abc
  13.     }
  14. }
  15. public static class cc
  16. {
  17.     public string gg(string s)
  18.     {
  19.         //gg
  20.     }
  21.     public static int zz(string s, string rx)
  22.     {
  23.         //zz
  24.     }
  25. }
  26. '@
  27. $className = 'cs'
  28. $functionName = 'abc'
  29. $pattern = "(?s)(?<=\bclass\s+$className\s*\{)[^}]*?(?<=\bfunction\s+$functionName[\s\n]*\()([\w\s,]*)[\)]"
  30. $match = [regex]::Match($s, $pattern)
  31. if ($match.Success)
  32. {
  33. Write-Output "函数 $functionName 在类 $className 中"
  34. }
  35. else
  36. {
  37. Write-Output "函数 $functionName 不在类 $className 中"
  38. }
  39. $functionName = 'cd'
  40. $pattern = "(?s)(?<=\bclass\s+$className\s*\{)[^}]*?(?<=\bfunction\s+$functionName[\s\n]*\()([\w\s,]*)[\)]"
  41. $match = [regex]::Match($s, $pattern)
  42. if ($match.Success)
  43. {
  44. Write-Output "函数 $functionName 在类 $className 中"
  45. }
  46. else
  47. {
  48. Write-Output "函数 $functionName 不在类 $className 中"
  49. }
复制代码

TOP

回复 2# jyswjjgdwtdtj

多谢大佬, 不用正则平衡组不行, 因为复杂的函数里面会有很多{}嵌套, 还有就是函数名前有各种修饰词,也要考虑

TOP

Set re = New regexp
re.pattern = "public class cs\n{.*?({.*}.*)*}"
re.multiline = True
re.ignorecase = True
cs = re.execute([yourc#code])(0)
If InStr(cs,"public string cd") <> -1 Then
    MsgBox "cd is in cs"
End If
If InStr(cs,"public int abc") <> -1 Then
    MsgBox "abc is in cs"
End If
成不成?

TOP

返回列表