using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^ *person *(?<person>.*?) *\| *age *(?<age>.*?) *\| *(?<someMarker>.*?) *\|gender *(?<gender>.*)$";
string input = @"person1 | Age 20 | M |Gender Male
person2 | Age 11 | |Gender Female
person3 | Age 23 | M |Gender Female
person4 | Age 32 | |Gender Male
person5 | Age 41 | M |Gender Male
person11| Age 28 | M |Gender Female
person12| Age 31 | M |Gender Male
person10| Age 33 | |Gender Male
person8 | Age 26 | |Gender Male";
RegexOptions options = RegexOptions.IgnoreCase | 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