正则表达式查找和替换换行标记

Mah*_*hai 2 .net c# regex

有谁知道如何使用正则表达式来查找和替换某些单词

<b>[Keyword]</b>
Run Code Online (Sandbox Code Playgroud)

我尝试使用,Regex.Replace()但它似乎只支持直接替换,而不是追加<b></b>到关键字的开头和最后.

例:

Hello World!
Run Code Online (Sandbox Code Playgroud)

关键词:

Hello
Run Code Online (Sandbox Code Playgroud)

输出:

<b>Hello</b> World!
Run Code Online (Sandbox Code Playgroud)

Ale*_*ici 6

你可以试试这个:

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        string
            input = "Hello World!",
            keyword = "Hello";

        var result = Regex
            .Replace(input, keyword, m => 
                String.Format("<b>{0}</b>", m.Value));
        Console.WriteLine(result);
    }
}
Run Code Online (Sandbox Code Playgroud)