gpt4 book ai didi

c# - RegularExpression C#,匹配组

转载 作者:太空宇宙 更新时间:2023-11-03 22:06:35 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com