且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-21 19:26:01

使用以下简单的正则表达式: \ [/?{0} \]

Use this simple regex: \[/?{0}\]

您的正则表达式将删除整个字符串

  • 您的正则表达式 \ [{0} \].*?\ [\/{1} \] 正在删除整个 [b] ... [/b] 字符串.这就是为什么从替换中得到空字符串的原因.

  • Your regex \[{0}\].*?\[\/{1}\] is removing the entire [b]...[/b] string. That's why you are getting an empty string from the replacement.

您需要删除的只是 [b] [b] .在常规正则表达式中,这很容易用 \ [/?b \] 表示,其中斜杠由?

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 ?

在参数化的正则表达式中,类似 \ [/?{0} \] 的东西将起作用.

In your parametrized regex, something like \[/?{0}\] will work.