Tag: bbcode

用于从字符串中删除特定BBCode的正则表达式

我正在尝试编写一种从输入字符串中删除特定BBCode的简单方法。 例如,我有一个输入: string input = “[b]Hello World![/b]”; 我希望能够做到: Remove(input, “b”); 得到一个输出: “Hello World!” 正则表达式真的不是我的强项。 我已经设法从谷歌拼凑以下内容: public static string Remove(string input, string code) { string pattern = string.Format(@”\[{0}\].*?\[\/{1}\]”, code, code); return Regex.Replace(input, pattern, string.Empty, RegexOptions.IgnoreCase); } 不幸的是,这给我的给定示例返回一个空字符串。 谁能告诉我如何纠正我的正则表达式以获得所需的输出? 谢谢