I have the next string bbcode type [MSG]abc[/MSG] which I want to replace by a friendly string....using a regex
My code works when the bbcode is in the first line only, but when I put some more text within the [MSG] tag with line breaks....it doesnt work....
What am doing wrong?
CODED TRIED
$("button").on("click", function(){
var textarea = $("#textarea").val();
var regex = /\[MSG\](.*)\[\/MSG]/ig;
textarea = textarea.replace(regex,"converted: $1 --");
$("div").text(textarea)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
hello [MSG]abc[/MSG]
<HR>
hello [MSG]a <BR>
bc[/MSG]
<HR>
<textarea id='textarea' rows=3>
hello [MSG]abc[/MSG]
/
hello [MSG]a
bc[/MSG]
</textarea>
<button>convert</button>
<div></div>
/\[MSG\]([^\]]*)\[\/MSG]/ig;or even/\[MSG\](.*|[\s\S]*)\[\/MSG]/ig?