【发布时间】:2015-09-07 12:51:31
【问题描述】:
我有一个String,它在<! --> 内有cmets,即<!comment1-->。
我想删除所有这些。
RE 是什么?
我试过了:
replaceAll("\\<!.*?\\-\\-\\>", "");
但它没有用。 我尝试循环和替换,它可以工作,但我正在寻找一个正则表达式
我已经尝试过该墨水中提到的 html.fromHtml 并且它不起作用。为此我提出了另一个问题here
例如下面的字符串
<style> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} @font-face {font-family:Webdings; panose-1:5 3 1 2 1 5 9 6 7 3;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:11.0pt; font-family:"Calibri",sans-serif;} a:link, span.MsoHyperlink {mso-style-priority:99; color:#0563C1; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:#954F72; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-compose; font-family:"Calibri",sans-serif; color:windowtext;} .MsoChpDefault {mso-style-type:export-only; font-family:"Calibri",sans-serif;} @page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in;} div.WordSection1 {page:WordSection1;} --></style>
【问题讨论】:
-
你试过
replaceAll("<!--(.*?)-->", "");吗? -
没有。那没用
-
试试
(?s)<!\\b.*?-->或者请发布您想要完全匹配的文本。