using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace regularExpression
{
class Program
{
private static void showMatch(string text, string expr)
{
Console.WriteLinel("The Expression:
" + expr);
MatchCollection mc = Regex.Matches(text, expr);
foreach (Match m in mc)
{
Console.WriteLine(m);
}
}
static void Main(string[] args)
{
string str = " Basit , Jamil, Faisalabad, phone 123123123 , social security no 123-13-123 ";
Console.WriteLine("Matching words start with 'B' and ends with 'T':");
showMatch(str, @"\bJ\S*l\b");// Words that start with R and end with n
showMatch(str, @"\b\w{6}\b");// Find six letter words
showMatch(str, @"\b\w{4,6}\b"); // Find all five and six letter words
showMatch(str, @"\d{3}-\d{2}-\d{4}"); //Social security number Format [xxx-xx-xxxx]
showMatch(str, @"\bJ\S*l\b");// Words that start with R and end with n
showMatch(str, @"\b\w{6}\b");// Find six letter words
showMatch(str, @"\b\w{4,6}\b"); // Find all five and six letter words
showMatch(str, @"\d{3}-\d{2}-\d{4}"); //Social security number Format [xxx-xx-xxxx]
Console.ReadKey();
}
}
}


No comments:
Post a Comment