using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^section_1:\s*(?<section_1>[a-z]+(?:\s&\s[a-z]+)*)\s*\|\s*section_2:\s*(?<section_2>[a-z]+(?:\s&\s[a-z]+)*)$";
string input = @"Section_1: hello & goodbye | section_2: kuku
Section_1: hello & goodbye & hola | section_2: kuku
Section_1: hello | section_2: kuku
";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase;
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