tags:

views:

36

answers:

2

I have a string:

[\n['-','some text what\rcontains\nnewlines'],\n\n

trying to parse:

Regex.Split(@"[\n['-','some text what contains newlines'],\n\n", @"\[\n\['(.*)','(.*)'],.*");

but the split return array seems to be null

i need to get part of text: "some text what contains newlines"

+2  A: 

You're looking for the Match function, which will give the the capture groups.

For example:

Regex.Match("[\n['-','some text what\rcontains\nnewlines'],\n\n", @"\[\n\['(.*)','(.*)'],.*", RegexOptions.Singleline).Groups[2].Value

RegexOptions.Singleline is necessary to force . to match \n.

SLaks
+1  A: 

The wildcard '.' does not recognize newlines by default. Use the RegexOptions.Singleline to specify that period should match newlines.

Also checkout Expresso, a great tool for working with C# Regex.

Rob Elliott