我有一个这样的java字符串:
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.
一种方法是使用内置字符串方法将字符串与regEx进行比较,但我不知道如何编写这些字符串。
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.
推荐答案建议使用正则表达式解析HTML(由于其允许的复杂性),但对于简单HTML和简单文本(没有文字的文本) < 或> in)这将有效:
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("<.*?>", "");更多推荐
删除两个字符之间的子字符串(java)
发布评论