Regular Expressions - RegEx
Intro
My notes on C#'s support for regular expressions via the System.Text.RegularExpressions namespace.
Â
Define The Pattern To Match
Â
You first need to define the RegEx pattern to be used. You can define the regex pattern as a string.
string pattern = @"^dog.*";
Regex rx = new Regex(pattern, RegexOptions.IgnoreCase);
Â
Execute Match
Â
DotNetFiddle: https://dotnetfiddle.net/OqEBzt
string input1 = "dog runs around\ndog2 runs around too.";
Match match = rx.Match(input1);
while (match.Success)
{
Console.WriteLine("'{0}' found at position {1}.", match.Value, match.Index);
match = match.NextMatch();
}