代码之家  ›  专栏  ›  技术社区  ›  Ganesha

使用regex将<uc>文本更改为文本

  •  0
  • Ganesha  · 技术社区  · 5 年前

    我需要使用regex将下面的标题转换为新标题,其中 <uc></uc>

    标题- this <uc>faq</uc> deals with <uc>sp</uc >

    新标题- This FAQ deals with SP

    2 回复  |  直到 5 年前
        1
  •  3
  •   juharr    5 年前

    你可以用下面的C代码

    string s = @"this <uc>faq</uc> deals with <uc>sp</uc>"; 
    string result = Regex.Replace(s, "<uc>(.*?)</uc>", m => m.Groups[1].Value.ToUpper());
    

    RegexOptions.IgnoreCase 如果你需要匹配 "<UC>something</UC>"

    注意:这不会像 "<uc>some<uc>stuff</uc></uc>"