string pattern = @"\b[cb]\w+";
c 또는 b 로 시작하는 단어를 찿는 패턴입니다.
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\b[cb]\w+";
string text = "codekiller is red, blue, test, blabla coding.";
MatchCollection matches;
Regex regex = new Regex(pattern);
matches = regex.Matches(text);
Console.WriteLine("Parsing '{0}'", text);
// Print
for (int ctr = 0; ctr < matches.Count; ctr++)
Console.WriteLine("{0}. {1}", ctr, matches[ctr].Value);
}
}
>>> 결과
Parsing 'codekiller is red, blue, test, blabla coding.'
0. codekiller
1. blue
2. blabla
3. coding