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
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Program to remove consonants from a String
- Program to remove vowels from a String
- C++ Program to remove spaces from a string
- How to add a parent to several tags in HTML ?
- Use of blockquote, q and cite tags in HTML
- HTML | Tags Complete Reference
- HTML | Subscript and Superscript Tags
- Remove characters from the first string which are present in the second string
- Remove "b" and "ac" from a given string
- Remove spaces from a given string
- Remove duplicates from a given string
- Remove comments from a given C/C++ program
- Remove extra spaces from a string
- Remove three consecutive duplicates from string
- Remove even frequency characters from the 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 firstname.lastname@example.org. 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.