/// <summary> /// 正則雙重過濾 /// splitKey1 第一個正則式匹配 /// splitKey2 匹配結果中再次匹配進行替換 /// </summary> /// <param name="content"></param> /// <param name="splitKey1"></param> /// <param name="splitKey2"></param> /// <param name="newChars"></param> /// <returns></returns> private static string GetReplace(string content, string splitKey1, string splitKey2, string newChars) { if (splitKey1 != null && splitKey1 != "" && splitKey2 != null && splitKey2 != "") { Regex rg = new Regex(splitKey1); System.Text.RegularExpressions.MatchCollection mc = rg.Matches(content); foreach (System.Text.RegularExpressions.Match mc1 in mc) { string oldChar = mc1.ToString(); string newChar = new Regex(splitKey2, RegexOptions.IgnoreCase).Replace(oldChar, newChars); content = content.Replace(oldChar, newChar); } return content; } else { if (splitKey2 != null && splitKey2 != "") { Regex rg = new Regex(splitKey2, RegexOptions.IgnoreCase); return rg.Replace(content, newChars); } } return content; }