This
[b]this text is bold[/b]
[i]this text is [b]italic[/b][/i]
parse out to this (in html)
<b>this text is bold[/b]<br><i>this text is [b]italic</i></b>
this text is bold[/b]
this text is [b]italic
using this function
function bbcode(input){
return input
.replace(/\[b\]([^]*)\[\/b\]/ig, '<b>$1</b>')
.replace(/\[i\]([^]*)\[\/i\]/ig, '<i>$1</i>');
}
I figure there has to be a problem with the regular expression finding each set of tags, but it appears that only the first bold tag and the last bold end tag are being parsed. Any idea how this can be fixed?
[^]*to capture? Unless I'm mistaken, it's exclusion is applying to nothing, so it's essentially the same as.*. You'll most likely want to make that clause non-greedy, by adding a?to make it[^]*?. Or, you may wish to actually exclude characters.[b]with<b>,[/b]with</b>and so on? Also,[^]has to be the most creative way to write.I've ever seen.[^]as I was working off examples and regex syntax is difficult to get a hold of. Once I got something that worked I stopped fussing with it.