- If you want to remove html tags from a string in java you need to use regex.
- Using java regex we can trim/remove html tags from given string.
- Lets see a java example program on how can we remove html code or html tags from a string in java.
- Input String : <B>hello</B>
- output: hello
#1: Java Example program to remove html tags from a string
- package com.instanceofjava.removehtmltags;
- /**
- * @author www.Instanceofjava.com
- * @category interview programs
- *
- * Description: java convert html to plain text/ trim html code from string in java
- *
- */
- public class RemoveHtmlTags {
- public static void main(String[] args) {
- String htmlStr = "<p>Java Program to remove html tags from a String</p>";
- System.out.println(htmlStr);
- htmlStr = htmlStr.replaceAll("\\<.*?\\>", "");
- System.out.println(htmlStr);
- }
- }
Output:
- <p>Java Program to remove html tags from a String</p>
- Java Program to remove html tags from a String
No comments