News

Internet - .Net user group technical events, emerging .Net technologies;
General - Eco-travel, health and fitness, current events;
Community - Active volunteer with Hands On Miami, Non-Profit Ways;
.Net Framework - Detected 3.5 SP1 .NET Framework. No update needed ;
creative zen converter

Tweets













Using static regular expression instance (C#)

In the .NET Framework and C# programming language. You can use a static variable initializer at the class level to instantiate the regular expression with the new operator. Then, you can access the Regex by its identifier and call methods such as Match, Matches, and IsMatch on it.  Static regular expressions show a performance advantage in timing tests. Also, static fields do not have an instance expression, so resolving the location of their memory storage is slightly faster.

using System;
using System.Text.RegularExpressions;

class Program
{
    static Regex _rWord = new Regex(@"R\w*");

    static void Main()
    {
        // Use the input string.
        // ... Then try to match the first word starting with capital R.

        string value = "This is a simple /string/ for Regex.";
        Match match = _rWord.Match(value);
        Console.WriteLine(match.Value);
    }
}

Out Put:

Regex

Saturday, February 06, 2010 10:10 AM

Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: