I recently stumbled across this problem while testing my C# program.
parsing “)” – Too Many )’s
Here is my code:
try
{
if (e.ChangedRange.Text.Contains(";") && Convert.ToBoolean(e.ChangedRange.Text.IndexOf(")", 1)))
{
if (!e.ChangedRange.Text.Contains(";") && !Convert.ToBoolean(e.ChangedRange.Text.IndexOf(")", 1)))
LuaLibrary.isParenthesesSemiColonError = false;
else
{
LuaLibrary.isParenthesesSemiColonError = true;
e.ChangedRange.SetStyle(error_red, ");", RegexOptions.IgnoreCase);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
What I’m doing here is, I’m checking to see if the current line (e.ChangedRange.Text) contains ‘;’ with the IndexOf a ‘)’. (And reversed on the second ‘if’ statement): I’m assuming they are both causing my issue; however, I don’t have a clue on how to fix it.
Help would be greatly appreciated.
The string in your call to
SetStyleis a regex pattern, so the)needs to be escaped. The problem is that parens are special characters in Regex. The regex parser is seeing the closing paren, but no opening paren to match it to.Try this: