C#で正規表現を使って連続する文字を検索する

2021年11月19日

書式
Match(String, String)
指定した入力文字列内で、指定した正規表現に最初に一致する箇所を検索します。
パラメーター
input 一致する対象を検索する文字列
pattern 一致させる正規表現パターン

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.Text.RegularExpressions;
namespace ConsoleApplicationSample
{
class Program
{
static void Main(string[] args)
{
// 正規表現で連続文字3個以上
string str = "s{3,}";
string target = "studyssskill";
//Matchメソッドで連続文字を指定して検索
Match res = Regex.Match(target, str);
Console.WriteLine("検索結果:" + res);
Console.ReadKey();
}
}
}
using System; using System.Text.RegularExpressions; namespace ConsoleApplicationSample { class Program { static void Main(string[] args) { // 正規表現で連続文字3個以上 string str = "s{3,}"; string target = "studyssskill"; //Matchメソッドで連続文字を指定して検索 Match res = Regex.Match(target, str); Console.WriteLine("検索結果:" + res); Console.ReadKey(); } } }
using System;
using System.Text.RegularExpressions;

namespace ConsoleApplicationSample
{
    class Program
    {
        static void Main(string[] args)
        {
            // 正規表現で連続文字3個以上
            string str = "s{3,}";
            string target = "studyssskill";

            //Matchメソッドで連続文字を指定して検索
            Match res = Regex.Match(target, str);
            Console.WriteLine("検索結果:" + res);

            Console.ReadKey();
        }
    }
}

実行結果
検索結果:sss

C#

Posted by arkgame