admin管理员组文章数量:1419648
I'm trying to convert square brackets on a form submit. I won't go into the form submission part as it's not required.
I had no problem replacing a new line with a <br />
tag like so:
new_line = message.replace(/\n/g, "<br />");
however what I'm trying to achieve now is convert [b] [/b]
to <strong> </strong>
. This is what I have tried so far but it doesn't seem to be working. I find regex's rather hard to grasp.
bold = message.replace(/\[b].*\[\/b]/g, '<strong>');
Can someone please point me in the right direction?
I'm trying to convert square brackets on a form submit. I won't go into the form submission part as it's not required.
I had no problem replacing a new line with a <br />
tag like so:
new_line = message.replace(/\n/g, "<br />");
however what I'm trying to achieve now is convert [b] [/b]
to <strong> </strong>
. This is what I have tried so far but it doesn't seem to be working. I find regex's rather hard to grasp.
bold = message.replace(/\[b].*\[\/b]/g, '<strong>');
Can someone please point me in the right direction?
Share Improve this question asked Sep 23, 2013 at 4:27 LodderLodder 19.8k11 gold badges63 silver badges102 bronze badges2 Answers
Reset to default 4Try this one...
bold = message.replace(/\[b\](.*?)\[\/b\]/g, '<strong>$1</strong>');
Try
'[b]asdf[/b]'.replace(/\[(\/?)b\]/g, '<$1strong>')
本文标签: javascriptjquery replace square bracketsStack Overflow
版权声明:本文标题:javascript - jquery replace square brackets - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745314834a2653104.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论