एक स्ट्रिंग से HTML टैग हटाना
हम HTML/XML को हटा सकते हैं जावास्क्रिप्ट . में रेगुलर एक्सप्रेशन का उपयोग करते हुए स्ट्रिंग में टैग . एचटीएमएल तत्व जैसे स्पैन, डिव इत्यादि बाएं और दाएं तीरों के बीच मौजूद हैं उदाहरण के लिए
वाक्यविन्यास
str.replace( /(<([^>]+)>)/ig, '');
उदाहरण-1
<html>
<body>
<script>
function removeTags(str) {
if ((str===null) || (str===''))
return false;
else
str = str.toString();
return str.replace( /(<([^>]+)>)/ig, '');
}
document.write(removeTags('<html> <body> Javascript<body> is not Java'));;
</script>
</body>
</html> आउटपुट
Javascript is not Java
उदाहरण-2
<html>
<body>
<script>
function removeTags(str) {
if ((str===null) || (str===''))
return false;
else
str = str.toString();
return str.replace( /(<([^>]+)>)/ig, '');
}
document.write(removeTags('<html> Tutorix is <script> the best <body> e-learning platform'));;
</script>
</body>
</html> आउटपुट
Tutorix is the best e-learning platform