Search code examples
javahtmlreplaceall

How to replace <a href='www.example.com'>Example:</a>?


String url : <a href='https://sample.com'>Example:</a>

I want to keep text Example: How to use replaceAll to do remove/replace with " "?


Solution

  • Particularly for your case:

    String url = "<a href='https://sample.com'>Example:</a>";
    String text = url.replaceAll("<a.*>\\b", "").replaceAll("</a>", ""));