Regular expression for matching functions
I am using the following regular expression (from http://www.simple-talk.com/dotnet/asp.net/regular-expressio开发者_高级运维n-based-token-replacement-in-asp.net/)
(?<functionName>[^\$]*?)\((?:(?<params>.**?)(?:,|(?=\))))*?)
it works fine, except when I what to include brackets within the parameters such as "<b>hello<b> renderHTML(""GetData(12)"") "
so I want "GetData(12)" instead I get "GetData(12".
Is there a way to ignore any matches if they are wrapped in double quotes?
There are ways to ignore the parens inside of quotes but this will not solve your problem. Function calls in C# cannot be matched with a regular expression . Regular expressions cannot match nested structures such as they way both parens and <
appear inside of a function call. To match these you need to use a grammar of sorts.
I while back I wrote a blog post which goes into a bit more detail about this problem
- http://blogs.msdn.com/b/jaredpar/archive/2008/10/15/regular-expression-limitations.aspx
I don't mean to be avoiding the answer here. But any answer to this question will just be broken by a slightly more complex (or sometimes even simpler) function call.
精彩评论