Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery替换方括号_Javascript_Jquery_Regex - Fatal编程技术网

Javascript jquery替换方括号

Javascript jquery替换方括号,javascript,jquery,regex,Javascript,Jquery,Regex,我正在尝试转换表单提交上的方括号。我不会进入表单提交部分,因为它不是必需的 用标记替换新行没有问题,如下所示: new_line = message.replace(/\n/g, "<br />"); 有人能给我指一下正确的方向吗?试试看 '[b]asdf[/b]'.replace(/\[(\/?)b\]/g, '<$1strong>') “[b]asdf[/b]”。替换(/\[(\/?)b\]/g,”) 试试这个 bold = message.replace(/\[

我正在尝试转换表单提交上的方括号。我不会进入表单提交部分,因为它不是必需的


标记替换新行没有问题,如下所示:

new_line = message.replace(/\n/g, "<br />");
有人能给我指一下正确的方向吗?

试试看

'[b]asdf[/b]'.replace(/\[(\/?)b\]/g, '<$1strong>')
“[b]asdf[/b]”。替换(/\[(\/?)b\]/g,”)
试试这个

bold = message.replace(/\[b\](.*?)\[\/b\]/g, '<strong>$1</strong>');
bold=message.replace(/\[b\](.*?\[\/b\]/g,$1);

如果bbcode
[b]hello world[/b][b][b]
无效,上述操作将导致无效html,从而意外损坏布局:
hello world
bold = message.replace(/\[b\](.*?)\[\/b\]/g, '<strong>$1</strong>');