Hai all how could I Replace Regex string html tag in textarea value with global attribute html example textarea value
<p style="color:red" id="demo1" class="demo1">text</p>
or
<p style="color:red">text</p>
.replace(/<p[^>]*>(.*?)<\/p>/g, "xxxxxxxxxxxxxxx")
How is the value for xxxxxxxxxxxxxxx
I am usinf this jQuery code :
$("button").on('click', function() {
var text = $('#demo').val();
if ( text.match() ){
text = text
.replace(/\<br\s*[\/]?>/g, "<br/>")
.replace(/\<hr\s*[\/]?>/g, "<hr/>")
.replace(/\<\/p><p>/g, "</p>\n\n<p>")
// this my problem with all attribute
// example for <p style="color:red" id="demo1" class="demo1">text</p>
/*
.replace(/<p[^>]*>(.*?)<\/p>/g, "<p[^>]*>\n$1<\/p>\n")
*/
;
return $('#demo').val(text);
}
});
textarea {
width: 80%;
height: 150px;
}
code {
color :red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="demo">
<p>Lorem ipsum dolor sit amet</p><p>Lorem ipsum dolor sit amet</p><p>Lorem ipsum dolor <br><br><br><br><br><br><br>sit amet</p><hr><hr><hr><hr><hr><hr><hr><hr><hr><p style="color:red" id="demo1" class="demo1">Lorem ipsum dolor sit amet</p>
</textarea>
<p>
<button>REPLACE</button>
</p>
<pre>
1. <code><br></code> to <code><br/></code> = ok
2. <code><hr></code> to <code><hr/></code> = ok
3. <code></p><p></code> to <code></p>\n\n<p></code> = ok
</pre>
Thank you in advance. sorry my English is not good
text
=\n
\n – Sisi Sajah Jul 14 '17 at 13:24