我有一些文字看起来像这样:
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
关于c# - RegularExpression C#,匹配组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8215315/