don't know exactly what you want to extract, sometimes regular expressions is not the perfect tool, you'd better off use yacc/lexbut see chapter 9 (.NET, downloadable pdf file) of Mastering Regular Expressions, 2nd Edition By Jeffrey E. F. Friedl
http://www.oreilly.com/catalog/regex2/there is an example of nested "("'s
http://www.oreilly.com/catalog/regex2/there is an example of nested "("'s
我也不是非得用正则表达式。 我的目的是解释上述函数脚本,并计算结果。我最先想到的是用正则表达式解析出函数和它的参数,如果参数是数字则存储,如果是另一个函数则进行递归操作。 我现在的问题是判断下一个参数是数值还是函数,并把它取出,这应该说是一个算法问题,而我以为可以利用正则表达式简化
果你需要动态地evaluate,你可以用CodeDom什么的,动态产生Assembly,参考Runtime C# Expression Evaluator
http://www.codeproject.com/csharp/runtime_eval.aspDynamic Code Generation and Code Compilation
http://www.codeproject.com/dotnet/dynacodgen.aspReflection Emit
http://www.ondotnet.com/pub/a/dotnet/excerpt/prog_csharp_ch18/index.html?page=6#refl_emit