일반적으로 사용되는 와일드카드 문자는 별표(*)입니다. 문자열에서 0개 이상의 문자를 나타냅니다.
다음 예에서 별표는 m으로 시작하고 e -
로 끝나는 단어를 일치시키는 데 사용됩니다.@”\bt\S*s\b”
다음은 완전한 코드입니다 -
예
using System;
using System.Text.RegularExpressions;
namespace Demo {
public class Program {
private static void showMatch(string text, string expr) {
MatchCollection mc = Regex.Matches(text, expr);
foreach (Match m in mc) {
Console.WriteLine(m);
}
}
public static void Main(string[] args) {
string str = "toss cross tacos texas";
Console.WriteLine("Matching words that start with 't' and ends with 's':");
showMatch(str, @"\bt\S*s\b");
}
}
} 출력
Matching words that start with 't' and ends with 's': toss tacos texas