C# – How to parse/split this line while keeping note of the order

cregexsplit

A little stuck here. I have a simple question I guess.

Given the following input:

 content {c:comment comment}this is actual content{c:comment etc} content

I need a way to get the content and comments seperated, but I need to now the order of them. So a simple regex doesn't work.

I want to get this:

 content
 {c:comment comment}
 this is actual content
 {c:comment etc}
 content

Somebody a clue?

Best Answer

As Artelius suggested:

Regex.Replace(
Regex.Replace(input, "({)", @"\r\n$1"),
                     "(})", @"$1\r\n");