1、 IsMatch()方法;IsMatch()方法實際上是一個返回Bool值得方法,如果測試字符滿足正則表達式返回True否則返回False。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace TestRegularExpressions
{
class Program
{
static void Main(string[] args)
{
string RegularText = "\\w{1,}@\\w{1,}\\.";
string groupEmail = "[email protected]";
if (Regex.IsMatch(groupEmail,RegularText))
{
Console.WriteLine(Regex.Replace(groupEmail, "@", "==="));
}
else
{
Console.WriteLine("未匹配成功!");
}
Console.ReadKey();
}
}
}
輸出:
3、Split()方法;Split()方法實際上是拆分的方法,根據匹配正則表達式進行拆分儲存在字符串數組中。 例子:輸出:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace TestRegularExpressions
{
class Program
{
static void Main(string[] args)
{
string RegularText = ";";
string groupEmail = "[email protected];[email protected];[email protected];[email protected];";
string[] Email;
Email = Regex.Split(groupEmail, RegularText);
foreach (string personEmail in Email)
{
Console.WriteLine(personEmail);
}
Console.ReadKey();
}
}
}