Mega Code Archive

 
Categories / C# Book / 11 Regular Expression Basics
 

0638 Regex class

Regex.Match searches within a larger string. The object that it returns has properties for the Index and Length of the match, as well as the actual Value matched: using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { Match m = Regex.Match("abcd", @"abcd?e"); Console.WriteLine(m.Success); Console.WriteLine(m.Index); Console.WriteLine(m.Length); Console.WriteLine(m.Value); Console.WriteLine(m.ToString()); } } The output: False 0 0