Regex.IsMatch Method
Regex.IsMatch 有六種多載方法
一、bool IsMatch(string input)
using System;
using System.Text.RegularExpressions;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string pattern = @"Bill";
string input = "Tom Mary Bill";
Regex regex = new Regex(pattern);
if (regex.IsMatch(input))
{
Console.WriteLine("I got Bill");
}
else
{
Console.WriteLine("I can't find Bill");
}
}
}
}
結果為
二、bool IsMatch(string input, int startat)
Indicates whether the regular expression specified in the Regex constructor finds a match in the specified input string, beginning at the specified starting position in the string.
三、static bool IsMatch(string input, string pattern)
using System;
using System.Text.RegularExpressions;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string pattern = @"Bill";
string input = "Tom Mary Bill";
if (Regex.IsMatch(input, pattern))
{
Console.WriteLine("I got Bill");
}
else
{
Console.WriteLine("I can't find Bill");
}
}
}
}
結果為
四、static bool IsMatch(string input, string pattern, RegexOptions options)
Indicates whether the specified regular expression finds a match in the specified input string, using the specified matching options.
五、static bool IsMatch(string input, string pattern, RegexOptions options, TimeSpan matchTimeout)
Indicates whether the specified regular expression finds a match in the specified input string, using the specified matching options and time-out interval.