Given a string str which contains some HTML tags, the task is to remove all the tags present in the given string str.
Input: str = “<div><b>Geeks for Geeks</b></div>”
Output: Geeks for Geeks
Input: str = “<a href=”https://www.geeksforgeeks.org/”>GFG</a>”
Approach: The idea is to use the Regular Expression to solve this problem. The following steps can be followed to compute the resultant string:
- Get the string.
- Since every HTML tags are inclosed in angular brackets(<>). Therefore use replaceAll() function in regex to replace every substring start with “<“ and ends with “>” to empty string.
- The function is used as:
String str; str.replaceAll("\\", "");
Below is the implementation of the above approach:
Geeks for Geeks
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- C++ Program to remove spaces from a string
- Program to remove consonants from a String
- Program to remove vowels from a String
- How to add a parent to several tags in HTML ?
- HTML | Subscript and Superscript Tags
- Use of blockquote, q and cite tags in HTML
- HTML | Tags Complete Reference
- Remove characters from the first string which are present in the second string
- Remove "b" and "ac" from a given string
- Remove comments from a given C/C++ program
- Remove spaces from a given string
- Remove duplicates from a given string
- Remove three consecutive duplicates from string
- Remove even frequency characters from the string
- Remove all occurrences of a character in a string
- Remove odd frequency characters from the string
- Remove first and last character of a string in Java
- Remove all characters other than alphabets from string
- Remove all duplicates from a given string in Python
- Remove the first and last character of each word in a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.