Home  >  Article  >  Backend Development  >  C# example of method to remove comments based on regular expressions

C# example of method to remove comments based on regular expressions

黄舟
黄舟Original
2017-05-28 10:06:041729browse

This article mainly introduces the method of C# based on regular rules to remove comments, and analyzes C#'s regular matching operation skills for comment symbols in the form of simple examples. Friends who need it can Refer to the following

The example of this article describes the method of removing comments in C# based on regular rules. Share it with everyone for your reference, the details are as follows:

string HoverTreeClearMark(string input)
{
  input = Regex.Replace(input, @"/\*[\s\S]*?\*/", "", RegexOptions.IgnoreCase);
  input = Regex.Replace(input, @"^\s*//[\s\S]*?$", "", RegexOptions.Multiline);
  input = Regex.Replace(input, @"^\s*$\n", "", RegexOptions.Multiline);
  input = Regex.Replace(input, @"^\s*//[\s\S]*", "", RegexOptions.Multiline);
  return input;
}

The above is the detailed content of C# example of method to remove comments based on regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn