如何从文本中删除标题

时间:2013-11-18 09:55:46

标签: java html

如何从下面显示的文字中删除标题。文本包含所有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>

1 个答案:

答案 0 :(得分:3)

但是,您不应该使用正则表达式来解析HTML。这里很合适:

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