using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"([^\s:\n][^:\n]*)\s+\:\s+\[\s*([^][]*)\s+]";
string input = @"Date : [ 2010-01-01 XX:XX:XX ] Age : [ 22 ] Sex : [ M ] : [ XXX ]
Height(cm) : [ 145 ] Weight(kg) : [ 56.4 ] Race : [ Hispanic ]
Spirometry : [ restrictive pattern ]
Treatment response : [ Negative ]
Tissue volume : [ Normal ]
Tissue volume
[ Normal RV ]
Diffusing capacity : [ Normal capacity ]
FVC Liters : [ 2.22 ] FVC Liters : [ 67 ] FVC Liters : [ 3.35 ]
FEV1 Liters : [ 1.96 ] FEV1 Liters : [ 66 ] FEV1 Liters : [ 2.06 ]
FEV1 / FVC % : [ 58 ] FEV1 / FVC % : [ 62 ]
DLCO mL/mmHg/min : [ 21.5 ] DLCO mL/mmHg/min : [ 102 ]
DLCO Adj mL/mmHg/min : [ 21.5 ] DLCO Adj mL/mmHg/min : [ 102 ]
RV/TLC % : [ 22 ]";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx