我有一个*.il文件。我想找到它中的所有非空方法(.method)。例如:
.class private auto ansi beforefieldinit MyApp.Program
extends [mscorlib]System.Object
{
//catch its body
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
//
.maxstack 8
IL_0000: nop
IL_0001: ret
}
//catch its body
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
//
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
}
//don't touch, it's empty
.method public hidebysig newslot virtual
instance string Invoke(string a) runtime managed
{
}
//......................................
}现在我用类字符串来做这件事。这是相当不理性的。我试过使用Regex,但是我想不出如何创建reg表达式来捕获
有人能帮我吗?
发布于 2012-10-21 16:02:15
不建议使用regex解析结构代码,这是不好的做法。
尝试使用regex模式
(\.method\s[^{]+?)(?=\s*{)(?!\s*{\s*})测试它这里。
要捕获每个方法的主体{...},请使用regex模式。
(\.method\s[^{]+{(?!\s*}).*?})测试它这里。
要了解有关正则表达式的更多信息,请访问regular-expressions.info
https://stackoverflow.com/questions/12999422
复制相似问题