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

72
Views
Multiple Regex on a single request

I wrote an app that shows last posts through API, and I'm using a regex to strip HTML tags from the result (that is actually plain text).

post.contentHtml retrieve the last post

example retrieved: "hi this is my last post <b>with</b> some html tags"

so my line is:

 post.contentHtml().replace(/<\/?[^>]+(>|$)/g, '')

example retrieved: "hi this is my last post with some html tags"

Now sometimes users post text with image URLs, and I want to replace all image URLs with a FontAwesome icons.

Is this possible with JavaScript?

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

0

found a solution by myself:

since i do not know how to replace with rendered html (actually if i put html it returns literally, i can do this with a text icon:

post.contentHtml().replace(/<\/?[^>]+(>|$)/g, '').replace(/(https?:\/\/\S+(\.png|\.jpg|\.gif))/g, '📷')
about 4 years ago · Juan Pablo Isaza Report

0

The simplest solution is to use match with regex. The sample is given below.

Regex: /<[^>]*>/g

Note: You can make a more complex regex.

const str = 'hi this is <img src="test" /> my  <span>with1</span> last post <b>with2</b> some html tags';
console.log(str.replace(/<[^>]*>/g, ""))

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!