正規表現を使用して、文字列 (または Stringbuilder) の特定のキーワードを選択したキーワードに置き換えています。ただし、単語全体のみを置き換える有効な正規表現パターンを作成できません。
たとえば、InputString = "fox foxy" があり、"fox" を "dog" に置き換えたい場合、出力は "dog dogy" になります。
「フォックス」のみを取り、「フォクシー」のままにする有効な正規表現パターンは何ですか?
public string Replace(string KeywordToReplace, string Replacement) /
{
this.Replacement = Replacement;
this.KeywordToReplace = KeywordToReplace;
Regex RegExHelper = new Regex(KeywordToReplace, RegexOptions.IgnoreCase);
string Output = RegExHelper.Replace(InputString, Replacement);
return Output;
}
ありがとう!