javascript - jquery replace square brackets - Stack Overflow

I'm trying to convert square brackets on a form submit. I won't go into the form submission p

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 badges
Add a ment  | 

2 Answers 2

Reset to default 4

Try this one...

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

Try

'[b]asdf[/b]'.replace(/\[(\/?)b\]/g, '<$1strong>')

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745314835a4622169.html

相关推荐

  • javascript - jquery replace square brackets - Stack Overflow

    I'm trying to convert square brackets on a form submit. I won't go into the form submission p

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信