I'm going to disagree with the answers below. If you do an AJAX call it should be once and it should get you a definition list of what conversions to perform. The actual conversions should be done on the client side, otherwise you're going to end up sending a request to the server with every keypress!
Here's an example of how you could do it:
// The array of regex patterns to look for
$format_search = [
/\[b\](.*?)\[\/b\]/ig,
/\[i\](.*?)\[\/i\]/ig,
/\[u\](.*?)\[\/u\]/ig
]; // note: NO comma after the last entry
// The matching array of strings to replace matches with
$format_replace = [
'<strong>$1</strong>',
'<em>$1</em>',
'<span style="text-decoration: underline;">$1</span>'
];
$('textarea').on('keyup', function() {
var preview = $(this).val().trim();
// Perform the actual conversion
for (var i = 0; i < $format_search.length; i++) {
preview = preview.replace($format_search[i], $format_replace[i]);
}
// show the preview in your div
$('#preview').html(preview);
});
Here's a demo fiddle. The replacement code is used from this answer.
My suggestion is that if you're going to use AJAX, use it to get the definitions for $format_search
and $format_replace
from a datasource rather than using it to parse the replacements.