Parsing BBCode in Javascript

前端 未结 2 653
旧巷少年郎
旧巷少年郎 2021-01-22 02:13

I am using this (http://coursesweb.net/javascript/convert-bbcode-html-javascript_cs) as my script for parsing BBCode. I have extended the BBCodes that it can process, however I

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-22 02:26

    JavaScript does not handle multi-line RegExp matches. Instead you have to use the [\s\S] trick described in this SO answer. Perhaps?

    /\[code\][\s\S]*\[code\]/
    

    Also RegExps probably isn't the best choice for parsing syntax. It's is extremely over complicated. I would suggest parsing the string and building an Abstract Syntax Tree then rendering the HTML from that.

提交回复
热议问题