Regex for removing a specific BBCode from a string

前端 未结 3 1929
陌清茗
陌清茗 2021-01-20 11:27

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         


        
3条回答
  •  一个人的身影
    2021-01-20 11:56

    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.

提交回复
热议问题