문자열이 −
라고 가정해 보겠습니다.string str = "The Shape of Water got an Oscar Award!";
다음 정규식을 사용하여 각 단어의 첫 글자를 표시하십시오 -
@"\b[a-zA-Z]"
다음은 전체 코드입니다 -
예
using System;
using System.Text.RegularExpressions;
namespace RegExApplication {
public class Program {
private static void showMatch(string text, string expr) {
Console.WriteLine("The Expression: " + expr);
MatchCollection mc = Regex.Matches(text, expr);
foreach (Match m in mc) {
Console.WriteLine(m);
}
}
public static void Main(string[] args) {
string str = "The Shape of Water got an Oscar Award!";
Console.WriteLine("Display first letter of each word!");
showMatch(str, @"\b[a-zA-Z]");
}
}
} 출력
Display first letter of each word! The Expression: \b[a-zA-Z] T S o W g a O A