views:

97

answers:

2

Hey, I have some text that is formatted like this:

[quote]foo text[/quote]

and I want to change it to this:

<div class="quote-text">foo text</div>

How can I do this with JS?

I'm using jQuery.

A: 
var myString = "blah blah [quote]test[/quote] foo bar [quote]another thing[/quote]";

myString.replace(/\[quote\](.*?)\[\/quote\]/g, '<div class="quote-text">$1</div>');
Amber
A: 

The following should do it:

string.replace(/\[quote\](.*?)\[\/quote\]/g, "<div class=\"quote-text\">".$1."</div>");
Marius
Probably better to use the non-greedy `.*?` in order to allow more than one quote in the text.
Amber
Thanks Dav, added that, and the g option. If you want to match [QUOTE]blahblah[/QUOTE] as well, add the i option
Marius