0
votes

I have a string containing some HTML content. I want to replace all the HTML tags and the content within them using Regex in java.

So for example <a>,<a href=""/>,</a> etc. should be removed.

I tried

str=str.replaceAll("<\\w*>","");

but it replaces only the first occurrence from the string.

How can I replace all the occurrences of this kind from the string. Thanks

1
possible duplicate of Stripping HTML tags in JavaMike Samuel

1 Answers

5
votes

can you try this,

str = str.replaceAll("<[^>]*>", "");