I have a paragraph of text coming from the backend that has
within curly brackets like so:
...some text { <br /> } { <br /> } ...more text
and some inline HTML styling like:
...some text <strong>some text</strong>
I need to remove all of these but need break where the line breaks are.
How can these be done with Regex?
I have a solution that doesn't require regex. However, since I don't know the content of your html, it might NOT work well. So, test it to make sure.
The first part is a simple text replace, so it doesn't require regex
htmlData.replaceAll('{ <br /> } ', '\n');
Then, you create a DOM element, insert all the html data into it, and get the innerText attribute that is the text data without the tags.
const p = '...some text <strong>some text</strong> more text <b>more</b> text...some text { <br /> } { <br /> } ...more text';
console.log("BEFORE: "+p);
let tmp = document.createElement("DIV");
// Replace into newlines.
tmp.innerHTML = p.replaceAll('{ <br /> } ', '\n');
// Get the text.
console.log("AFTER: "+tmp.innerText);