Click here to Skip to main content
15,171,439 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Can not get why my Regex class can not instantiate. The regular expression seems to be fine, but i'm getting error message when calling "BuildStructure":

System.ArgumentException : parsing "[(.*?;)(([(if)(while)(for)]).*?\(.*?\){({.*?})*?})]" - Too many )'s.

Here is the code:
C#
class CodeStructureBuilder
{
private const String REGULAR_EXPRESSION =
            @"[(.*?;)([(if)(while)(for)]\s*?\(.*?\){({.*?})*?})]";

public CodeStructureBuilder() {}

public void BuildStructure()
{
    Regex regex = new Regex(REGULAR_EXPRESSION);
}
}
Posted

1 solution

You either have an extra backslash:
"[(.*?;)([(if)(while)(for)]\s*?\(.*?\){({.*?})*?})]"
becomes
"[(.*?;)([(if)(while)(for)]\s*?(.*?\){({.*?})*?})]"
or one too few:
"[(.*?;)([(if)(while)(for)]\s*?\(.*?\){({.*?}\)*?})]"
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900