使用场景
匹配嵌套字符串,如匹配类中的大括号,HTML中的尖括号等。
(?'group'exp)
(?'-group'exp)
(?(group)(?!)) //判断栈中是否为空,为空则匹配成功,否则失败
匹配函数体的正则表达式
string regexMethodContentStr = @"{[^{}]*((?<open>{)|(?<-open>})|[^{}])*(?(open)(?!))[^{}]*}" ;
//匹配实例函数
string regexMethodStr = string.Concat(@"public\s+\S+\s+\S+\([\s\S]*?\)" , @"\s*" , regexMethodContentStr);
//匹配静态函数
string regexStaticMethodStr = string.Concat(@"public\s+static\s+\S+\s+\S+\([\s\S]*?\)" , @"\s*" , regexMethodContentStr);
使用上面的正则表达式可以方便的匹配到代码文件中的具体函数,获取函数后然后进一步获取函数的访问域,函数名,参数信息等,本上曾写过一个注释自助添加器,有兴趣可以看看。
其它资源
python正则表达式指南:
http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html