C#でRegexOptions.IgnoreCaseを指定して大文字小文字を無視する
書式
public static System.Text.RegularExpressions.Match Match (string input,
string pattern, System.Text.RegularExpressions.RegexOptions options);
指定した一致オプションを使用して、入力文字列内で、指定した正規表現に最初に一致する箇所を検索します。
RegexOptions 列挙型 IgnoreCase
検索時に大文字と小文字を区別しないことを指定します。
使用例
using System;
using System.Text.RegularExpressions;
namespace ConsoleApplicationSample
{
class Program
{
static void Main(string[] args)
{
string str = "y";
string target = "STUDY";
//RegexOptions.IgnoreCaseを指定して、大文字小文字を無視
Match res = Regex.Match(target, str, RegexOptions.IgnoreCase);
Console.WriteLine("結果: "+res);
Console.ReadKey();
}
}
}
using System;
using System.Text.RegularExpressions;
namespace ConsoleApplicationSample
{
class Program
{
static void Main(string[] args)
{
string str = "y";
string target = "STUDY";
//RegexOptions.IgnoreCaseを指定して、大文字小文字を無視
Match res = Regex.Match(target, str, RegexOptions.IgnoreCase);
Console.WriteLine("結果: "+res);
Console.ReadKey();
}
}
}
using System; using System.Text.RegularExpressions; namespace ConsoleApplicationSample { class Program { static void Main(string[] args) { string str = "y"; string target = "STUDY"; //RegexOptions.IgnoreCaseを指定して、大文字小文字を無視 Match res = Regex.Match(target, str, RegexOptions.IgnoreCase); Console.WriteLine("結果: "+res); Console.ReadKey(); } } }
実行結果
結果: Y