删除两个字符之间的子字符串(java)

编程入门 行业动态 更新时间:2024-10-11 13:26:23
本文介绍了删除两个字符之间的子字符串(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)

本文发布于:2023-11-28 21:59:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   字符   两个   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!