using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace _17._4Csharp中正则表达式的匹配
{
class Program
{
static void Main(string[] args)
{
string pattern = @"^(0349|0349-)\d{7,8}$";
string[] input = { "010-12345678","0349-1234567","03491234567","075912345678","13886133650"};
foreach( string outstr in input)
{
//静态方法
// bool mybool = Regex.IsMatch(outstr.Trim(),pattern);
// if (mybool) Console.WriteLine(outstr + "是宿州市固话");
// else Console.WriteLine(outstr+"不是宿州固话");
//实例化方法
Match mymatch = Regex.Match(outstr.Trim(),pattern);
if (mymatch.Success) Console.WriteLine(outstr + "是宿州市固话");
else Console.WriteLine(outstr+"不是宿州市固话");
}
Console.ReadKey();
}
}
}