Daniel
Daniel

Reputation: 8368

RegularExpression C#, matching group

I have some text looking like this:

My arbitrary content....

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

I want to find all blocks starting with:

```c#

and ending with:

```

and replace it with the content between these start and end tags, so that the result becomes:

My arbitrary content....

public class Foo
{
    //Some code
}

My other arbitrary content....

How would that look?

Upvotes: 1

Views: 77

Answers (1)

Mark Byers
Mark Byers

Reputation: 838066

It sounds like you just want to remove the triple backtick style markers and leave the rest of the document unchanged.

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

See it working online: ideone

Upvotes: 4

Related Questions