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?
试试这个......
bold = message.replace(/\[b\](.*?)\[\/b\]/g, '<strong>$1</strong>');
尝试
'[b]asdf[/b]'.replace(/\[(\/?)b\]/g, '<$1strong>')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.