using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^path(?:(?=\?)(?:[?&]foo=(\d*)(?=[&#]|$)|(?![?&]foo=)[^#\n])+)?(?=#|$)";
string input = @"path
pathbreak
path?foo=123
path?foo=-123
invalid?foo=1
path?foo=123&bar=abc
path?bar=abc&foo=123
path?bar=foo
path#anchor
path#foo=bar
path?foo=123#bar
path?foo=123abc
path?foo";
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