删除两个字符之间的子字符串(java) [英] Removing a substring between two characters (java)

查看:95
本文介绍了删除两个字符之间的子字符串(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆