Regular expression find and replace to wrap tags

后端 未结 2 1334
独厮守ぢ
独厮守ぢ 2020-12-10 20:56

Does anyone know how to use regex to find and replace certain word with

[Keyword]

I tried to use Regex.Replace() but it

2条回答
  •  温柔的废话
    2020-12-10 21:34

    You may try this:

    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("{0}", m.Value));
            Console.WriteLine(result);
        }
    }
    

提交回复
热议问题