Podge
Podge

Reputation: 467

Regular expression for matching functions

I am using the following regular expression (from http://www.simple-talk.com/dotnet/asp.net/regular-expression-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?

Upvotes: 1

Views: 291

Answers (1)

JaredPar
JaredPar

Reputation: 754525

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

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.

Upvotes: 1

Related Questions