Home > Enterprise >  Multiple Regex on a single request
Multiple Regex on a single request

Time:09-25

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?

CodePudding user response:

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, '           
  • Related