I want to be able to match a HTML tag in a given string. The string could be like this

<a href = "http://learnmore.com">Learn </a>.

I have a replace function that replaces the HTML tag with whitespace when I hard code the tag, but I want a regex pattern that can match any characters between the < and > special characters. I have tried a lot, searched a lot on google, but to no avail. I have read posts on the internet that HTML should not be parsed by regex, but here I am only trying a simple matching, so using regex should be OK.

Recommended Answers

All 2 Replies

You can try replaceAll("<.+?\\>", "")

You can try replaceAll("<.+?\\>", "")

Wow!!! Thank you so much this worked fantastic. I have been looking for a solution for this all day long. Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.