gpt4 book ai didi

java - 如何仅删除文本中的标题

转载 作者:行者123 更新时间:2023-12-01 23:25:36 25 4
gpt4 key购买 nike

如何从下面显示的文本中仅删除标题。文本包括所有 html 标签,也包括标题标签,所以也许我可以尝试使用开始标题标签和结束标题标签来删除标题文本,并保留其他所有内容。做这个的最好方式是什么?

<HTML><HEAD>
<META NAME="Docdate" CONTENT="05/02/2011">
<META NAME="m_title" CONTENT="TWO SECURITY GUARDS HACKED TO DEATH DURING A FIGHT">
<META NAME="m_author" CONTENT="">
<TITLE>MALAYSIA NEWS -- GENERAL NEWS -- 05/02/2011 -- TWO SECURITY GUARDS HACKED TO DEATH DURING A FIGHT</TITLE>
</HEAD><BODY BACKGROUND="#FFFFFF">
<PRE>
05/02/2011

POLICE-FIGHT

TWO SECURITY GUARDS HACKED TO DEATH DURING A FIGHT





KUALA LUMPUR, Feb 5 (Bernama) -- Two security guards were hacked to death in

a fight that broke out at Damansara Perdana construction site last night.

Both men, aged 20 and 26, were found dead at the scene with slash wounds on

their bodies in the 8.20pm incident.

Petaling Jaya OCPD ACP Arjunaidi Mohammed said the fight started following

an argument involving a security guard and several foreign workers at the site.

"One of them had an argument with several of the workers. He then called two

of his friends who are also security guards but working in other areas.

"A group of 12 to 15 foreign workers, carrying sharp weapons, then attacked

them," he told reporters at the scene today.

The other security guard managed to flee to safety, he added.

"The foreign workers had also left the area. We have picked up a security

guard in the area and two Indonesian workers to have their statements taken," he

said, adding that a manhunt was underway for the suspects.

-- BERNAMA

NMR AKT JS





</PRE>
<BODY></HTML>

最佳答案

然而,不应该使用正则表达式来解析 HTML 是很常见的。这里适合:

String html = ...;
String withoutTitle = html.replaceAll("\\<TITLE\\>(.+)?\\</ ?TITLE\\>", "<TITLE> </TITLE>");

关于java - 如何仅删除文本中的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20044803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com