I\'m trying to write a simple method for removing specific BBCodes from an input string.
For example, where I have an input of:
string input = \"[b]H
Use this simple regex: \[/?{0}\]
Your regex is removing the whole string
Your regex \[{0}\].*?\[\/{1}\] is removing the entire [b]...[/b] string. That's why you are getting an empty string from the replacement.
What you need is to remove only the [b] and [b]. In normal regex, this is expressed quite simply with \[/?b\], where the slash is made optional by the ?
In your parametrized regex, something like \[/?{0}\] will work.
If you sure that both starting and trailing special symbol must occur and you don't want them to be in a result, you can use positive look back ((?<=(your symbols here))) and positive look ahead ((?=(your symbols here))) for specified characters.
Complete answer will look like this:
(?<=(\[{0}\])).*(?=(\[\/{1}\]))
The below regex would capture the string Hello World! inside the second group.
^(.*?)((?<=])[^[]*)(.*)$
DEMO
So replace all your input string with the second captured group.