1.把p标签的内容提取出来并去掉前后空格
let str= '<p style="border:1px solid red ;" > This is a rich text string. </p><p> Another paragraph. </p><p style="border:1px solid red ;" > This is a rich text string. </p><p> Another paragraph. </p><p style="border:1px solid red ;" > This is a rich text string. </p><p> Another paragraph. </p><p style="border:1px solid red ;" > This is a rich text string. </p><p> Another paragraph. </p>';
const str1= str.replace(/(?<=(<p[^>]*?>)).*?(?=(<\/p>))/g, (match, p2) => {
return match.trim()
});
console.log(str1);