RT。例如:有一段代码:
                  EMU0      : in bit;  -- must be type in for compliance enable
                                       -- non-JTAG type is inout
                  EMU1      : in bit;  -- must be type in for compliance enable
                                       -- non-JTAG type is inout
                  RSV0      : in bit;
怎样用正则把注释过滤掉,其他的输出。注释就是"--"符号后边的!
                

解决方案 »

  1.   


                string pattern = @"(?is)(?:--).*?(?:\n)";
                string replacement = "\n";
                string input = @"EMU0 : in bit; -- must be type in for compliance enable
      -- non-JTAG type is inout
      EMU1 : in bit; -- must be type in for compliance enable
      -- non-JTAG type is inout
      RSV0 : in bit;";
                input = Regex.Replace(input, pattern, replacement);
                Console.WriteLine(input);
    /*
    EMU0 : in bit; 
      EMU1 : in bit;
      RSV0 : in bit;
    */
      

  2.   

    不考虑包在""中的--的话,这样就可以了
    string test = @"EMU0 : in bit; -- must be type in for compliance enable
      -- non-JTAG type is inout
      EMU1 : in bit; -- must be type in for compliance enable
      -- non-JTAG type is inout
      RSV0 : in bit;";
    Regex reg = new Regex(@"--.*");
    string result = reg.Replace(test, "");
    richTextBox2.Text = result;