Removing a substring between two characters (java)

2019-01-15 19:30发布

I have a java string such as this:

String string = "I <strong>really</strong> want to get rid of the strong-tags!";

And I want to remove the tags. I have some other strings where the tags are way longer, so I'd like to find a way to remove everything between "<>" characters, including those characters.

One way would be to use the built-in string method that compares the string to a regEx, but I have no idea how to write those.

1条回答
不美不萌又怎样
2楼-- · 2019-01-15 20:13

Caution is advised when using regex to parse HTML (due its allowable complexity), however for "simple" HTML, and simple text (text without literal < or > in it) this will work:

String stripped = html.replaceAll("<.*?>", "");
查看更多
登录 后发表回答