I want to split the string "This is regarding the problem of {pro} in {statement}"
I want to get output is
This is regarding the problem of
{pro}
in
{statement}
I want to split the string "This is regarding the problem of {pro} in {statement}"
I want to get output is
This is regarding the problem of
{pro}
in
{statement}
You could try this regex:
([^{]+|{[^}]*})
It matches each group of characters which are defined by either:
{
; or{
character, followed by any number of characters which are not }
, all followed by }
Here's a simple regex that will insert a new line before and after your token matches by overriding the evaluator:
string output = Regex.Replace(input, @"{\S+}", m => string.Format(@"{1}{0}{1}", m.Value, '\n'));
The output variable will have a newline after. You can then just do a string split if you need the output in an array of strings.
string[] lines = output.Split('\n');