C # Regex Error Unterminated [] set

I am getting this error (I am using C #):

parsing "(- [[.?]]) | (- [[.]" - Unterminated [] set.

When trying to add multiple Lua comment code. This is what it should be:

--[[
  Hello
]]

      

However, when I take out the ']]' at the end of this Regex:

(--[[.*?]])|(--[[.*)

      

it will give me this error. However, if I add ']]' in the above example:

(--[[.*?]])|(--[[.*]])

      

it works great.

Here's the complete code:

Regex CustomCommentRegex1, CustomCommentRegex2, CustomCommentRegex3;
CustomCommentRegex1 = new Regex(@"--.*$", RegexOptions.Multiline | RegexCompiledOption);
CustomCommentRegex2 = new Regex(@"(--[[.*?]])|(--[[.*)", RegexOptions.Singleline | RegexCompiledOption);
CustomCommentRegex3 = new Regex(@"(--[[.*?]])|(.*]])", RegexOptions.Singleline | RegexOptions.RightToLeft | RegexCompiledOption);

      

'CustomCommentRegex2' where I get this "Unterminated [] set" error. I have a problem if I add ']]' at the end of "CustomCommentRegex2". It will highlight the text above and inside the "- [[]]" comments; anyway, the problem is the "Unterminated [] set" error.

+3


source to share


1 answer


On the Regex website

Because we want to do more than just search for literary pieces of text, we have to reserve certain characters for special uses. the regular expressions discussed in this lesson have 11 characters with special meanings: open square bracket [ , backslash \, cart ^, dollar sign $, period or period., vertical bar or pipe character, question mark?, asterisk, or a star *, plus a + sign to open the round bracket (and close the round bracket). These special characters are often referred to as "metacharacters".



Escape the parentheses with \

(--\[\[.*?]])|(--\[\[.*)

      

+7


source







All Articles