Skip to main content
 首页 » 编程设计

c#之RegularExpression C#,匹配组

2024年02月23日14duanxz

我有一些文字看起来像这样:

My arbitrary content.... 
 
```c# 
public class Foo 
{ 
    //Some code 
} 
``` 
My other arbitrary content.... 

我想找到以以下开头的所有 block :

```c# 

结束于:

``` 

并将其替换为这些开始和结束标记之间的内容,这样结果就变成了:

My arbitrary content.... 
 
public class Foo 
{ 
    //Some code 
} 
 
My other arbitrary content.... 

那看起来怎么样?

请您参考如下方法:

听起来您只想删除三重反引号样式标记并保持文档的其余部分不变。

text = Regex.Replace( 
      text, 
      @"^```c#\r?\n(.*?)```\r?\n", "$1", 
      RegexOptions.Singleline | RegexOptions.Multiline); 

在线查看它:ideone