Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove the tag from link

display

console log

I want to remove the tag(e.g. <p> <h1>) and leave only link

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

At first, I thought of cutting by detecting the tag <p>, but I think there will be a non-tag <p> case I don’t know how to do that.

sorry for my English skill.

>Solution :

You can use a regular expression to identify HTML tags in the input string. Replacing the identified HTML tag with null. This will result remove any queries with <> and </> and anything inside of the < > tags.

Here’s an example of this below:

function removeTags(str) {
    if ((str===null) || (str==='')) return false;
    else str = str.toString();
    return str.replace( /(<([^>]+)>)/ig, '');
}
removeTags('<p>youtu.be/TJR10xK</p>');

Then log the input with console.log(removeTags('<p>youtu.be/TJR10xK</p>')), what ever you want to do afterwards.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading