Skip to main content

best way to remove html tags from a String in java




but between < and &gt: - it is not the tags - so we want to keep "head" in between ?

        String htString = "&lt;head&gt; bla bla</head>;";


String res = htString.replaceAll("(<[^>]+>)|(&[^;]+;)","");

System.out.println(res);

Comments