[英]Matching multiline text using regular expression in java
我的輸入示例是:
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 15">
<meta name=Originator content="Microsoft Word 15">
<link rel=File-List href="detailedFoot_files/filelist.xml">
我想做的是我要選擇整個html標簽並將其替換為某些內容。 所以我正在使用正則表達式
<html.*>
如果我以Mather.DOTALL方式使用此正則表達式,則會替換整個文本輸入。
我不知道該怎么做。 任何幫助將不勝感激。
如果您只想替換起始html
標記,則以下內容將替換它:
String replaced = Pattern.compile("<html[^>]+>", Pattern.DOTALL)
.matcher(input).replace("my replacement for html tag");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.