Skip parsing the BBCode inside the CODE tag

前端 未结 1 1910
梦谈多话
梦谈多话 2021-01-27 13:10

I\'m parsing the BBCode using the regex in order to replace it into the HTML. I\'m stuck right now because of the [code] tags parsing.

Basicall

相关标签:
1条回答
  • 2021-01-27 14:01

    If you are going to parse from the exterior in, you need something like this for your code tag

    (?:\[code])(.*)(?=(?:\[\/code]))
    

    But as other have mentioned, you should be very careful with you do with this because you can not guarantee what is coming to you, it may be malformed and then you will end up with a mess of tags or even an incomplete mixture of parsed and unparsed bbcodes.

    Even the code that i just wrote will fail if you have two [/code][/code].

    0 讨论(0)
提交回复
热议问题