jQuery javascript regex Replace
with \n

前端 未结 5 524
独厮守ぢ
独厮守ぢ 2020-12-02 11:46

How do i write a regex to replace
or
with \\n. I\'m trying to move text from div to textarea, but don\'t want

5条回答
  •  抹茶落季
    2020-12-02 12:38

    var str = document.getElementById('mydiv').innerHTML;
    document.getElementById('mytextarea').innerHTML = str.replace(//gi, "\n");
    

    or using jQuery:

    var str = $("#mydiv").html();
    var regex = //gi;
    $("#mydiv").html(str.replace(regex, "\n"));
    

    example

    edit: added i flag

    edit2: you can use /]*>/gi which will match anything between the br and slash if you have for example

提交回复
热议问题