我的输入示例是:
<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的方式使用这个正则表达式,整个文本输入都会被替换。
我想不出该怎么做。任何形式的帮助都将不胜感激。
发布于 2016-06-12 13:37:54
这个正则表达式似乎捕获了您正在寻找的内容。
pattern = "\<html[^>]*>?(.*)"">
发布于 2016-06-12 13:28:20
如果您只想替换开始html标记,则以下内容将替换它:
String replaced = Pattern.compile("<html[^>]+>", Pattern.DOTALL)
.matcher(input).replace("my replacement for html tag");https://stackoverflow.com/questions/37770963
复制相似问题