CODEKILLER

반응형

> Pattern 설명

RegularExpressions 정규식 Match
RegularExpressions 정규식 Match

CodeKiller\. Man "CodeKiller.Man"라는 문자열을 찾습니다. "." 문자는 모든 문자와 일치하는 와일드카드가 아닌 리터럴 마침표로 해석되도록 이스케이프됩니다.
(Woman)? "Woman"이라는 0개 또는 1개의 문자열을 찾습니다.
using System;
using System.Text.RegularExpressions;

public class Example
{
    public static void Main()
    {
        string input = "The example test lines :" +
                       "'CodeKiller.Man' Test line" +
                       "'CodeKiller.Man' Test line" +
                       "'CodeKiller.ManWoman' Test line";

        string pattern = @"CodeKiller\.Man(Woman)?";
        MatchCollection matches = Regex.Matches(input, pattern);
        foreach (Match match in matches)
            Console.WriteLine(" match.Value : '{0}', match.Index : {1}.",
                              match.Value, match.Index);
    }
}

 

반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band