Parsing BBCode in Javascript

前端 未结 2 651
旧巷少年郎
旧巷少年郎 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:43

    This does the trick for me: (updated this one too to avoid confusion)

    \[code\]([\s\S]*?)\[\/code\]
    

    See regexpal and enter the following:

    [code]
        code....
    [/code]
    
    [code]code.... [/code]
    

    Update: Fixed the regex to the following and this works in the Chrome Console for me:

    /\[code\]([\s\S]*?)\[\/code\]/g.exec("[code]hello world \n[/code]")
    

提交回复
热议问题