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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.