Search This Blog

Loading...

Monday, August 30, 2010

How to remove HTML tags from a Java String?

Some times we need to remove HTML tags from a java string before publishing it to the page. We can achieve this by using a regular express. Sample code is given below for your reference.

public class RemoveTags{
    public static void main(String a[]){
        String text = "<b>I dont want this to be bold<\b>";
        text = text.replaceAll("\\<.*?\\>", "");
        System.out.println(text);
    }
}

Output:

I dont want this to be bold

No comments:

Post a Comment