简体   繁体   English

C#正则表达式匹配三引号“”

[英]C# regular expression match triple quotes “”"

I have a text file that contain 3 quotations (""") in various lines in text. It also have 6 blank spaces before that in every line. I have tried doing @"\\s{6}\\"{3}"; 我有一个文本文件,该文件在文本的各行中包含3个引号(“”“)。在每行之前还有6个空格。我尝试执行@” \\ s {6} \\“ {3}”; and various cases, but it seems like c# doesn't like when it sees 3 quotations mark together. 以及各种情况,但是当c#看到3个引号一起出现时,c#似乎不喜欢它。 What I'm trying to do is to find that and add a new line after. 我想做的就是找到它,然后添加新行。

This is what i have tried: 这是我尝试过的:

 string pattern4 = @"\s{6}"{3}";

 var match4 = Regex.Match(body, pattern4, RegexOptions.Multiline);
 while (match4.Success)
 {
    string index = """;
    output.Insert(index, "\r\n");
 }

Sample Input : 样本输入

  """Step:    33    And I enter 

  Step:    34    And I set the  

Desired Output: 所需输出:

  """

  Step:    33    And I enter    

  Step:    34    And I set THE

To escape a quote inside a verbatim string (starts with @) use double quotes. 要在逐字字符串(以@开头)中转引号,请使用双引号。 Also there is a Regex.Replace method that you could use like this: 还有一个Regex.Replace方法,您可以像这样使用:

string input = @"      """"""Step:    33    And I enter 

Step:    34    And I set the  ";

string pattern = @"\s{6}""{3}";
string replacement = "\"\"\"\r\n";

string output = Regex.Replace(input, pattern, replacement);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM