繁体   English   中英

如何仅从文本中删除标题

[英]How can I remove just the title from a text

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM