My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
C# CODE EXAMPLE created on Thursday, September 02, 2010 permalink
Extension method for checking regex in one line
This simple extension method allows you to check strings against regular expressions in one line.
using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;

namespace TestRegex2342343
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> texts = new List<string>()
            {
                "233-2887",
                "2332887",
                "442-1121",
                "",
                null
            };

            foreach (var text in texts)
            {
                if (text.MatchesRegex("^[0-9]{3}-[0-9]{4}$"))
                    Console.WriteLine(text + " matches");
                else
                    Console.WriteLine(text + " does NOT match");
            }
            Console.ReadLine();
        }
    }

    public static class Helpers
    {
        public static bool MatchesRegex(this string text, string regex)
        {
            if (text == null || regex == null)
                return false;
            else
            {
                Match match = Regex.Match(text, regex);
                return match.Success;
            }
        }
    }
}
need markup?