c# - Regex for removing a specific BBCode from a string -
c# - Regex for removing a specific BBCode from a string -
i'm trying write simple method removing specific bbcodes input string.
for example, have input of:
string input = "[b]hello world![/b]"; i want able do:
remove(input, "b"); and output of:
"hello world!" regex isn't strong suit. i've managed piece next google:
public static string remove(string input, string code) { string pattern = string.format(@"\[{0}\].*?\[\/{1}\]", code, code); homecoming regex.replace(input, pattern, string.empty, regexoptions.ignorecase); } unfortunately returns empty string given example.
can advise me on how can right regex desired output?
thanks
use simple regex: \[/?{0}\]
your regex removing whole string
your regex \[{0}\].*?\[\/{1}\] removing entire [b]...[/b] string. that's why getting empty string replacement.
what need remove [b] , [b]. in normal regex, expressed quite \[/?b\], slash made optional ?
in parametrized regex, \[/?{0}\] work.
c# regex bbcode
Comments
Post a Comment