I am trying to create RegEx to match C# comments (the double slash kind). The RegEx I have created almost works perfectly, except if there is a line that has just two backslashes and no actual comment, it starts matching the next line, which it shouldn’t do. Here is my regex:
(?![\n\r])\s?//[\w\W].+
Here is my test data:
using System;
// This is a comment
public class test
{
// this is also a comment
// Hello!
//
}
My RegEx matches everything as expected except the line that has just the //. The RegEx I have matches the // and the final brace, which isn’t right.
This
will match to the end of the line and no more.