How to write BB codes? I know it is easy, but the problem is: when you write [B]тест[/B] , everything is in order, and when [B]тест... then the whole text is bold. How to make a filter, so that if there is [B] , but there is no [/B] , then [B] removed from the text? Or it gave an error: end the tag.

  • At the idea level: with a regular expression, count the number of open tags minus the number of closed tags. If something is not enough - to add. - ling

1 answer 1

  1. make a replacement for the regular expression for all paired tags.
  2. remove all that did not pass autochange.

The last item, for example, is:


I mean, delete all the square brackets and everything in between.