using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"((\/\/[^\n\r]*)|(\/\*[^\*\/]*\*\/))";
string input = @"/* asdadasd
addds
asdasdas */
// asdasdasdasdasdas
/* asdasdasd */
asdasdasda
asdas
das
das
das
da
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader(""c:\\test.txt"");
while((line = file.ReadLine()) != null)
{
Console.WriteLine (line);
counter++;
}
file.Close();
// Suspend the screen.
Console.ReadLine();";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx