Mega Code Archive

 
Categories / C# Book / 11 Regular Expression Basics
 

0640 Compiled Regular Expressions

Instantiate a Regex object with the pattern and then call instance methods: using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { Regex r = new Regex(@"test?"); Console.WriteLine(r.Match("test")); Console.WriteLine(r.Match("tests")); } } The output: test test