우리의 문자열은 -
string str = " My make ";
다음 정규식을 사용하여 하위 문자열 "make"를 찾습니다.
@"\bmake\b"
다음은 전체 코드입니다 -
예시
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("Found:" + m);
}
}
public static void Main(string[] args) {
string str = "My make";
Console.WriteLine("Matching words start with 'm' and ends with 'e':");
showMatch(str, @"\bmake\b");
}
}
}
출력
Matching words start with 'm' and ends with 'e': The Expression: \bmake\b Found:make