How to replace string and ignore underscore? the string structure should stay as is. I dont want remove the underscore. just replace the 'world' with 'sharp'. and only for whole words
string[] sentences =
{
"Hello",
"helloworld",
"hello_world",
"hello_world_"
};
foreach (string s in sentences)
{
string pattern = String.Format(@"\b{0}\b", "world"); // whole case ignore underscore
string result = Regex.Replace(s, pattern, "charp");
Console.WriteLine(s + " = " + result);
}
output should be:
// Hello
// helloworld
// hello_charp
// hello_charp_