Reputation: 185
Below is the code
var str = '<p>first occurrence</p> can have multiple lines of ln or new line code etc <p>another p</p> and then again <p>another code in p </p>';
expected result with regex or simple jquery:
first occurrence can have multiple lines of ln or new line code etc <p>another p</p> and then again <p>another code in p </p>
Upvotes: 1
Views: 1529
Reputation: 171669
Don't use regex on html ... put the string into a newly created element and manipulate that element
var $div = $('<div>').html(str);
$div.find('p:first').unwrap()
str = $div.html()
Upvotes: 0
Reputation: 975
var str = document.getElementById('test').innerHTML.trim();
// var str = '<p>first occurrence</p> can have multiple lines of ln or new line code etc <p>another p</p> and then again <p>another code in p </p>';
str = str.replace(/<p>(.*?)<\/p>/, '$1');
console.log(str);
<div id="test">
<p>first occurrence</p> can have multiple lines of ln or new line code etc <p>another p</p> and then again <p>another code in p </p>
</div>
Upvotes: 5