Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
Remove HTML tags but implement line breaks from text (Regex and Javascript)

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!