using System.Text.RegularExpressions;
public static void Main()
string address="台中市西屯區台灣大道四段1727號";
Regex regexWithoutSection = new Regex(@"(大道|路|街|巷|弄|衖)(.*?)(號)");
Match matchWithoutSection = regexWithoutSection.Match(address);
if (matchWithoutSection.Success)
Regex regexWithSection = new Regex(@"(段)(.*?)(號)");
Match matchWithSection = regexWithSection.Match(address);
if (matchWithSection.Success)
Console.WriteLine("替換後的地址: " + regexWithSection.Replace(address, "$1**$3"));
Console.WriteLine("替換後的地址: " + regexWithoutSection.Replace(address, "$1**$3"));
Console.WriteLine("找不到匹配的內容。");