Sunday 17 April 2016

c# regular expression

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;


namespace ConsoleApplication3
{
    public class expression
    {
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Y/N");
                string abc = Console.ReadLine();
                //if (Regex.IsMatch(abc, "^[Yy]$"))         Y/y
                //if (Regex.IsMatch(abc, "^[A-Za-z]$"))     single letter
                //if (Regex.IsMatch(abc, "^[0-9]{2}$"))     double digits
                //if (Regex.IsMatch(abc, "^(ab|bc|md|sk)$"))  abc or bc or md or sk
                if (Regex.IsMatch(abc, "^([A-Z][0-9]){3}$"))    //POSTAL CODE
                {
                    Console.WriteLine("you entered Y");
                }
            }
        }
   
    }
}


No comments:

Post a Comment