Tanuj Wadhwa
Tanuj Wadhwa

Reputation: 2045

Regex replace all in java

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

Upvotes: 0

Views: 263

Answers (1)

Thalaivar
Thalaivar

Reputation: 23622

can you try this,

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

Upvotes: 5

Related Questions